2010-01-14 42 views
1

我想通過jquery將文本框的值設置爲null。我試圖設置文本框的值 - jQuery

onclick="$('#c_album').val('TEST VALUE');" at the submit button 

$('input#c_album').val('hello'); - in the script section 

欣賞assitance

感謝 戴夫

[編輯] - 這是我使用

$('#submit').bind('click',(function(){ 
     $('#src_box').val('hello'); 
    }); 

回答

0

代碼如果文本框的ID #c_alcum那麼你可以使用

$("#c_album").val('hello'); 

雖然您可以在ID選擇器前使用標籤選擇器,但不需要使用它,因爲ID在文檔中是唯一的。

如果您想在ajax函數完成後設置該值,那麼您可以將此代碼插入到ajax請求的回調函數中。

編輯

你把所有這些代碼的文檔準備事件中

$(function(){ 
    // All code goes here 
}); 

同時刪除點擊數處理程序,並做jQuery的方式像

$("#yourbuttonid").click (function(){ 
}); 

$("#yourbuttonid").bind ("click" , function() { 
}); 

您不能在文本框中輸入空值。您可以將裏面的一個空字符串值,像

$("#c_album").val(''); 
+0

不會出於某種原因,試圖太:( – dave 2010-01-14 10:28:34

+0

你能爲此提供更多的代碼? – rahul 2010-01-14 10:29:05

+0

@pulse:它的搜索框,現在當用戶點擊搜索按鈕,他提出與他的搜索和搜索文本框中的值應爲空 – dave 2010-01-14 10:30:47

0
$(function(){ 
    $('#mybutton').click(function(e){ 
     $('input#c_album').val('hello'); 
    }); 
}); 

是應該工作的一般方法。不知道更多的代碼,很難更具體。

1
$(function(){ 
     $('#btnSubmit').bind('click', function(){ 
      $('input#c_album').val('hello'); 
// OR 
      $('#c_album').val('hello'); 
// OR 
      $('input[id=c_album]').val('hello'); 
     }); 
    }); 
0

它的工作,錯誤是,沒有ID爲文本框

<input type='text' name='text' id='text'> 

感謝所有的你..

0
$('#submit').bind('click',(function(){ 
     $('#src_box').val('hello'); 
    }); 

有一個在這個代碼中的問題,所以試試這個 -

$('#submit').bind('click',function(){ 
     $('#src_box').val('hello'); 
    }); 

問題是你有在函數()之前使用了一個'(')。 但現在它會正常工作:)

0
$.ajax({ 
    type: "GET", 
    url: "fetchBeaconName", 
    data: "beaconMajorId=" + val, 
    async: true, 
    success: function (data) { 
     $.each(data.beaconList, function() { 
      $("#beaconName").val(this.beaconName); 
     }); 
    }, 
    error: function (data) { 
     alert("No values found..!!"); 
    } 
}); 
+0

請解釋你做了什麼 – GGO 2017-10-09 08:05:03