Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.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 - Fatal编程技术网

Javascript 若字符串是某物,那个么值为空

Javascript 若字符串是某物,那个么值为空,javascript,Javascript,在javascript中,我如何编写这样一个函数:若字符串为“Select client”,则地址和联系人号码字段应为null或空白。我已经有了这个功能,如果选择了客户端名称,那么地址和联系号码字段将使用rails的填充器gem自动输入 $('#client_id').change(function(){ $.ajax({ url: "/fetch_client", type: "POST", data:

在javascript中,我如何编写这样一个函数:若字符串为“Select client”,则地址和联系人号码字段应为null或空白。我已经有了这个功能,如果选择了客户端名称,那么地址和联系号码字段将使用rails的填充器gem自动输入

 $('#client_id').change(function(){
        $.ajax({
            url: "/fetch_client",
            type: "POST",
            data: "id="+$(this).attr('value'),
            dataType: "json",
            success: function(data, textStatus, xhr){
                $('#client_address').attr('value',data.client_address);
                $('#client_contact_number').attr('value',data.client_contact_number);

            },
            error: function(xhr, textStatus, errorThrown){

            }

        });
  }); 

有人能帮我一下吗,因为我是javascript新手?

我不太明白你到底在问什么。要根据特定值检查字符串吗?实际上,选择客户端是一个下拉列表。当我点击提示信息“Select Client”时,地址和联系人号码字段应为空。我必须将空值传递给错误块。change方法涉及下拉列表。这回答了你的问题吗?我在错误块中写了这段代码。你能告诉我这是否正确吗?错误:函数(xhr,textStatus,errorhorn){//alert(“error”);$(“#client_address”).value=“”;$(“#client_contact_number”).value=“”}它应该是
$(“#client_address”).val(“”)
而不是
$(“#客户地址”)。value=“”
 $('#client_id').change(function(){
       if ($(this).val() == "Select client") {
                $('#client_address').attr('value', "");
                $('#client_contact_number').attr('value', "");
       } else {

        $.ajax({
            url: "/fetch_client",
            type: "POST",
            data: "id="+$(this).attr('value'),
            dataType: "json",
            success: function(data, textStatus, xhr){
                $('#client_address').attr('value',data.client_address);
                $('#client_contact_number').attr('value',data.client_contact_number);

            },
            error: function(xhr, textStatus, errorThrown){

            }

        });
     }
  });