Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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
如何使用javascript根据下拉选择(带有外部链接)禁用/启用按钮?_Javascript_Jquery_Html_Button_Drop Down Menu - Fatal编程技术网

如何使用javascript根据下拉选择(带有外部链接)禁用/启用按钮?

如何使用javascript根据下拉选择(带有外部链接)禁用/启用按钮?,javascript,jquery,html,button,drop-down-menu,Javascript,Jquery,Html,Button,Drop Down Menu,我有一个下拉列表,其中有一些选项可供选择,这将导致一个外部链接。到目前为止,这一切正常,但我希望在未选择任何内容时禁用该按钮。作为一个非开发人员,我还不能把它组合起来。有什么想法吗 函数goToNewPage(){ if(document.getElementById('target').value){ 打开(document.getElementById('target').value); } } 请选择一个 第八章 谷歌 Search.com 狗堆 我建议您可以使用: // bindin

我有一个下拉列表,其中有一些选项可供选择,这将导致一个外部链接。到目前为止,这一切正常,但我希望在未选择任何内容时禁用该按钮。作为一个非开发人员,我还不能把它组合起来。有什么想法吗

函数goToNewPage(){
if(document.getElementById('target').value){
打开(document.getElementById('target').value);
}
}

请选择一个
第八章
谷歌
Search.com
狗堆

我建议您可以使用:

// binding the anonymous function of the on() method as
// the event-handler for the 'change' event:
$('#target').on('change', function(){

    // finds the next sibling <input> element with the '.gobutton'
    // class-name:
    $(this).next('.gobutton')
      // and sets its 'disabled' property to true if
      // the value of the <select> is equal to the 'Please select one'
      // string:
      .prop('disabled', this.value === 'Please select one');

// triggers the 'change' event on page load in order that the
// anonymous function disables the <input> on page-load:
}).change();

请选择一个
第八章
谷歌
Search.com
狗堆

谢谢,但我还没看到任何效果。它应该添加到我已经拥有的函数之外,对吗?如果你看一下(现在已更正)的代码片段,它应该告诉你如何在当前函数的旁边使用它。很酷,现在我看到它可以工作了,谢谢!缺少jquery库的源。现在我只需要弄清楚如何将它嵌入到我的wordpress主题(Avada)中,这样它也能在那里工作。你也知道如何解决这个问题吗?我恐怕不知道,我上次看Wordpress已经快十年了,甚至当我使用Wordpress的时候,我也有点痛苦。这个问题可能已经被回答了。好的,我会查一查。我也找到了一些信息。无论如何谢谢你!