合并两个功能? [英] Merging two functions?

查看:65
本文介绍了合并两个功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以合并这两个函数?


< script type =" text / javascript">

function showdiv(pass ){

setTimeout(''showdiv2("''+ pass +''")'',750);

}

function showdiv2(pass){

var divs = document.getElementsByTagName(''div'');

for(i = 0; i< divs.length; i ++) {

if(divs [i] .id.match(pass)){

if(document.getElementById)

divs [i] .style.visibility =" visible";

}

else {

if(document.getElementById)

divs [i] .style.visibility =" hidden";

}

}

}

< / script>

谢谢! ;)

Is it possible to merge two functions like these?

<script type="text/javascript">
function showdiv(pass) {
setTimeout(''showdiv2("''+pass+''")'', 750);
}
function showdiv2(pass) {
var divs = document.getElementsByTagName(''div'');
for(i=0;i<divs.length;i++){
if(divs[i].id.match(pass)){
if (document.getElementById)
divs[i].style.visibility="visible";
}
else {
if (document.getElementById)
divs[i].style.visibility="hidden";
}
}
}
</script>
Thanks! ;)

推荐答案



Charles写道:

Charles wrote:

是否可以合并这两个函数?


< script type =" text / javascript">

function showdiv(传递){

setTimeout(''showdiv2("''+ pass +''")'',750);

}

function showdiv2(pass){

var divs = document.getElementsByTagName(''div'');

for(i = 0; i< divs.length; i ++ ){

if(divs [i] .id.match(pass)){

if(document.getElementById)

divs [i ] .style.visibility =" visible";

}

else {

if(document.getElementById)

divs [i] .style.visibility =" hidden";

}

}

}

< / script>


谢谢! ;)
Is it possible to merge two functions like these?

<script type="text/javascript">
function showdiv(pass) {
setTimeout(''showdiv2("''+pass+''")'', 750);
}
function showdiv2(pass) {
var divs = document.getElementsByTagName(''div'');
for(i=0;i<divs.length;i++){
if(divs[i].id.match(pass)){
if (document.getElementById)
divs[i].style.visibility="visible";
}
else {
if (document.getElementById)
divs[i].style.visibility="hidden";
}
}
}
</script>
Thanks! ;)



是的。只需将第一个函数的内容附加到第二个底部附近的某个位置(假设'就是你想要它的位置),然后更改

的第一个参数setTimeout(),所以计时器将调用它自己的

包含函数。我不太确定你的计时器

实际服务器的目的,但也没有什么可以阻止你添加一个

条件语句,并嵌套setTimeout( )功能里面

那个。


如果你能解释一下你想要实现的目标,那可能会更容易

to帮助你。


与此同时,这里有一个类似的例子,该函数使用一个

计时器以设定的间隔调用自己,文字闪光。请

注意,这并不完美,因为

初学者没有启动/停止功能,但这是一个可以帮助你的简单例子。


谢谢。


Daz。

Yes. Simply append the contents of the first function somewhere near
the bottom of the 2nd (assuming that''s where you want it), and change
the first argument of the setTimeout(), so the timer will call it''s own
containing function. I am not quite sure of the purpose that your timer
actually servers, but there''s also nothing stopping you from adding a
condition statement, and nesting the setTimeout() function inside of
that.

If you can explain what you are trying to achieve, it might be easier
to help you.

It the meantime, here''s a similar example, where the function uses a
timer to call upon itself at set intervals, to make text flash. Please
note, this is not perfect as there is no start/stop function for
starters, but it is a simple example which might help you.

Thanks.

Daz.




Charles写道:

Charles wrote:

是否可以合并这样的两个函数?


< script type =" text / javascript">

函数showdiv(pass){

setTimeout(''showdiv2("''+ pass +''")'',750); < br $>
}

函数showdiv2(传递){

var divs = document.getElementsByTagName(''div'');

for(i = 0; i< divs.length; i ++){

if(divs [i] .id.match(pass)){

if( document.getElementById)

divs [i] .style.visibility =" visible";

}

else {

if(document.getElementById)

divs [i] .style.visibility =" hidden" ;;

}

}

}

< / script>
Is it possible to merge two functions like these?

<script type="text/javascript">
function showdiv(pass) {
setTimeout(''showdiv2("''+pass+''")'', 750);
}
function showdiv2(pass) {
var divs = document.getElementsByTagName(''div'');
for(i=0;i<divs.length;i++){
if(divs[i].id.match(pass)){
if (document.getElementById)
divs[i].style.visibility="visible";
}
else {
if (document.getElementById)
divs[i].style.visibility="hidden";
}
}
}
</script>



function showdiv(pass){


var

function showdiv(pass) {

var


pass = pass;


var divs = document.getElementsByTagName(''div'');


var pos = 0;


继续();


函数proceed(){

if(divs [pos] .id.match(
pass = pass;

var divs = document.getElementsByTagName(''div'');

var pos = 0;

proceed();

function proceed() {
if (divs[pos].id.match(


这篇关于合并两个功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆