我有以下html:
<div class="custom_title" contenteditable="true" maxlength="50">
WRITE YOUR CUSTOM TITLE HERE
</div>
然后我这样做:
$("#search_wiki").on("click", function() {
myGoogle();
});
哪个电话:
var termS;
function myGoogle() {
termS = $(".custom_title").html();
console.log(termS);
然而,当我更改该div上的文本时,控制台仍然会给我旧文本而不是新文本
答案 0 :(得分:0)
它在代码段中运行良好:
$("#search_wiki").on("click", function() {
myGoogle();
});
var termS;
function myGoogle() {
termS = $(".custom_title").html();
console.log(termS);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="custom_title" contenteditable="true" maxlength="50">
WRITE YOUR CUSTOM TITLE HERE
</div>
<h1 id="search_wiki">Search wiki</h1>
答案 1 :(得分:0)
只需在就绪事件内的事件中添加jQuery,如下所示:
<script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
$(document).ready(function() {
$("#search_wiki").on("click", function() {
myGoogle();
});
});
和你做的html:
<div class="custom_title" contenteditable="true" maxlength="50">
WRITE YOUR CUSTOM TITLE HERE
</div>
<h1 id="search_wiki">Search wiki</h1>