我真的不明白如何将这两个代码放到一起。 我想把它捣碎给togheter所以它有效。
代码1:
<script type="text/javascript">
function myfunction(obj){
if (obj.checked)
{
alert("checked");
/// I want to put code 2 here
}
else
{
alert("Unchecked");
/// I want to put code 2 here
}
}
</script>
&#13;
代码2:
<script>
window.setInterval(function() {
httpGetAsync('test.php', function(text) {
if (document.getElementById("text").innerHTML >= 700) {
window.open("www.site.kom", "_blank");
alert("Test 2");
}
});
}, 7000);
</script>
&#13;
答案 0 :(得分:1)
为什么不这样做?
<script type="text/javascript">
function myfunction(obj){
if (obj.checked)
{
alert("checked");
otherFunction()
/// I want to put code 2 here
}
else
{
alert("Unchecked");
otherFunction()
/// I want to put code 2 here
}
}
function otherFunction() {
window.setInterval(function() {
httpGetAsync('test.php', function(text) {
if (document.getElementById("text").innerHTML >= 700) {
window.open("www.site.kom", "_blank");
alert("Test 2");
}
});
}, 7000);
}
</script>
&#13;
答案 1 :(得分:0)
正如@Slaks所指出的那样,您需要了解功能。现在,请看下面的代码。
<script type="text/javascript">
function mySecondFunction() {
window.setInterval(function() {
httpGetAsync('test.php', function(text) {
if (document.getElementById("text").innerHTML >= 700) {
window.open("www.site.kom", "_blank");
alert("Test 2");
}
});
}, 7000);
}
function myfunction(obj){
if (obj.checked)
{
alert("checked");
mySecondFunction();
}
else
{
alert("Unchecked");
mySecondFunction();
}
}
</script>