Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从php和onchange变量加载Javascript_Javascript_Php_Function_Onchange - Fatal编程技术网

从php和onchange变量加载Javascript

从php和onchange变量加载Javascript,javascript,php,function,onchange,Javascript,Php,Function,Onchange,我有一个从php加载一些div id的脚本,每x秒重新加载一次新值。。我想在脚本中实现一个onchange值,以便在本例中艺术家改变时触发加载一个新变量,但我不知道如何。。 剧本是: setInterval(function(){ cache: false, $("#artist").load("test.php #artist"); $("#song").load("test.php #song"); }, 2000); 我需要知道艺术家是否改变了,然后使用我在这里找

我有一个从php加载一些div id的脚本,每x秒重新加载一次新值。。我想在脚本中实现一个onchange值,以便在本例中艺术家改变时触发加载一个新变量,但我不知道如何。。 剧本是:

setInterval(function(){
    cache: false,
    $("#artist").load("test.php #artist");
    $("#song").load("test.php #song");
}, 2000);
我需要知道艺术家是否改变了,然后使用我在这里找到的包装器代码从php加载一个新变量

如果我对输入框使用相同的示例: 它起作用了。。但是我不知道如何使用第一部分从php中提取的艺术家使其工作

我试着这样做:

<script type="text/javascript">
    setInterval(function(){
        cache: false,
        $("#artist").load("test.php #artist").onchange(wrapper.set(this.value));
        $("#song").load("test.php #song");
    }, 2000);
</script>
还有很多其他组合,但都不起作用。。你能帮帮我吗

PS:请记住,我是javascript的初学者


谢谢您的回答。

您在这里错过了一些东西。我建议您使用firefox中的firebug来调试code@InGodITrust对不起,伙计,小错别字没注意到我的坏。。我删除了它。你还有一个^^^试试这个我还没有测试这个脚本,所以它可能会工作。如果你的问题中没有html代码。如果艺术家是一个文本框,请告诉我编辑答案。这似乎可以做到,非常感谢,但它每2秒都会给我所有html数据。。我在php文件中关于艺术家的语法是echo$artist;我怎样才能使它只为艺术家工作,而且只有在名称改变的情况下才能工作?它现在工作得很完美。。非常感谢。如果我想在这个脚本中使用test.php中的$artist变量,那么如何实现这一点,而不是获取div?我只是好奇:也请投赞成票;在你的php文件中,你可以只回显艺术家的名字,而不需要其他任何东西,没有html标记,没有脚本。如果你只是读取了名字而不是div,那么变量数据将包含艺术家的名字,不需要额外的努力来提取它。
setInterval(function(){
    cache: false,
    $.get('test.php',function(data){
     var artist = $('<div>' + data + '</div>').find('div#artist').html();
     if(artist != $('#artist').html()){
          $('#artist').html(artist );
          wrapper.set(artist)
    } //in here I assumed #artist is a div or span,... if its a textbox change it to $('#artist').val()
    });
    $("#song").load("test.php #song");
}, 2000);
setInterval(function(){
    cache: false,
    $.get('test.php',function(data){
     var artist = $('<div>' + data + '</div>').find('div#artist').html();
     if(artist != $('#artist').html()){
          $('#artist').html(artist );
          wrapper.set(artist)
    } //in here I assumed #artist is a div or span,... if its a textbox change it to $('#artist').val()
    });
    $("#song").load("test.php #song");
}, 2000);