簡體   English   中英

jQuery回調無法識別jQuery函數調用

[英]Jquery callback does not recognize jquery function call

我有一個JavaScript函數發出AJAX獲取請求和回調設置來更新div的內容。 唯一的問題是在回調函數中出現錯誤Uncaught TypeError:對象#HTMLDivElement沒有方法'html'

由於某種原因,jQuery $(“ selector”)僅返回div而不返回jquery對象。

這是代碼

//HTML
<select id="dimensions" name="dimensions" onchange="getDimention()">
    <option value="default">Select One</option>
....
</select>
 <div id="dim" > No Dimentions added yet</div>

//JS
function getDimention() {
   var eSelect = document.getElementById('dimensions');
  server.Dimention(eSelect.value, onGetDimentionSuccess); //make AJAX call
}
function onGetDimentionSuccess(response) {
   $('dim').html(response);
}

您需要使用適當的類似CSS的選擇器:

$('#dim').html(response);

我想你的意思是-您忘記了ID選擇器的#

$('#dim').html(response);

ID必須附加

嘗試這個

$('#dim').html(response);

具有的ClassName

 $('.dim').html(response); // Id dim was a class name

您是否正在運行原型或任何其他JavaScript框架?

嘗試jQuery.noConflict(),然后使用jQuery('#dim')。html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM