18910140161

如何在html页面中实现查找功能

顺晟科技

2021-06-16 10:20:13

344

前台效果:

1c47607531c598617a5e8004471ebc1.png

超文本标记语言

2

3

5

6

8

Div class=' container ' style=' z-index : 999 ' id=' Search Div '

' div class='关键字-搜索'

查找:

input id=' key ' type=' text ' style=' width : 200 px;'占位符='关键词' /

a href=' JavaScript : void(0);'class=' prev ' onclick=' WordSearch(1)' I class=' c-icon '/I/a

a href=' JavaScript : void(0);'class=' next ' onclick=' WordSearch()' I class=' c-icon '/I/a

/div

/div

相关教程推荐:html教程

射流研究…

2

3

5

6

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

脚本/搜索功能

var oldKey0=

var索引0=-1;var oldCount0=0

var new flag=0;

var CurrentLength=0;

函数单词搜索(flg) {

var key=$('#key ').val();//取键值

if(!键){

返回;//键为空则退出

}

getArray();

焦点下一个(flg);

}

函数focusNext(flg) {

if (newflag==0) {//如果新搜索,索引清零

index0=0

}

if(!flg) {

if (oldCount0!=0) {//如果还有搜索

if (index0 oldCount0) {//左边如果没走完,走左边

焦点移动(索引0);

索引0

} else if (index0==oldCount0) {//都走完了

index0=0

焦点移动(索引0);

索引0

}

else {

index0=0//没确定

焦点移动(索引0);

索引0

}

}

} else {

if (oldCount0!=0) {//如果还有搜索

if (index0=oldCount0 index0 0) {//左边如果没走完,走左边

索引0-;

焦点移动(索引0);

} else if (index0==0) {//都走完了

index0=oldCount0

索引0 -

焦点移动(索引0);

}

}

}

}

函数getArray() {

新标志=1;

$('.对比。结果')。移除CLaSS(' RES ');

var key=$('#key ').val();//取键值

if(!键){

oldKey0=

返回;//键为空则退出

}

if (oldKey0!=key || $(' .当前')。长度!=currentLength) {

//重置

index0=0

var index=0;

$('.对比。结果')。每个(函数(){

$(这个)。替换为($(this).html());

});

pos0=new Array();

if ($(').对比色环绕')。具有类别(' current '){

currentLength=$(' .当前')。长度;

$('.电流。对比')。每个(函数(){

$(这个)。html($(this).html().replace(new RegExp(key,' gm '),' span id=' result '(index)' class=' result ' ' key '/span ');//替换

});

} else {

$('.对比色环绕')。添加CLaSS(' current ');

currentLength=$(' .当前')。长度;

$('.对比')。每个(函数(){

$(这个)。html($(this).html().replace(new RegExp(key,' gm '),' span id=' result '(index)' class=' result ' ' key '/span ');//替换

});

}

//$('#key ').val(键);

oldKey0=键

//$('.对比。结果')。每个(函数(){

//$(这个)。家长('。对比色环绕')。添加CLaSS(' current ');

//pos0.push($(this).偏移量()。top);

//});

//pos0.push($(').对比结果:eq(2)').偏移量()。top - $(' .对比结果:eq(2)').家长('。对比')。偏移量()。top);

oldCount0=$(' .对比。结果')。长度;

新标志=0;

}

}

函数focusMove(index0) {

$('.对比结果:eq(' index0 ').家长('。对比色环绕')。添加CLaSS(' current ');

$('.对比结果:eq(' index0 ').添加CLaSS(' RES ');

var top=$(' .对比结果:eq(' index0 ').偏移量()。$(' .对比结果:eq(' index0 ').家长('。对比')。滚动ToP();

var intop=top - $(' .对比结果:eq(' index0 ').家长('。对比')。偏移量()。顶端

$('.对比结果:eq(' index0 ').家长('。对比')。动画({ scrollTop: intop },200);

if ($(').对比结果:eq(' index0 ').家长('。对比')。scrollTop()==0) {

$('html,body ').动画({ scrollTop: top - 200 },200);

} else {

$('html,body ').动画({ scrollTop: $(').对比结果:eq(' index0 ').家长('。对比')。偏移量()。top - 200 },200);

}

}

$('#key ').change(function () {

if ($('#key ').val()=='') {

index0=0

$('.对比。结果')。每个(函数(){

$(这个)。替换为($(this).html());

});

oldKey0=

}

});

/script

相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航