你有一個簡單的需要生成一個新的窗口與textarea的內容。基於用戶想要的格式類型,他們可以按下一個按鈕來改變一些textarea的文本以適應他們的需要。但是我在實現.replace命令時遇到了麻煩 - 儘管我試圖在此論壇上關注示例。jquery替換語法不起作用
<body>
<div id="diagoutput"> </div>
<a onclick="combine()" href="report_output.html" id="link" target="_blank"><input type="button" value="Generate a report window"><br>
<textarea rows="10" cols="40" placeholder="Diagnosis" id="outPut3">I love the sun devils</textarea><br>
</body>
這裏是我的js代碼段中不更換預期文本
function combine(){
var diag=$("#outPut3").text().replace(/sun devils/g, "WILDCATS");
var textToPass=' \nNEW TEXT:\n'+diag.value;
localStorage.setItem("myText", textToPass);
};
我是新的jQuery,所以我的一些嘗試複製別人已經做可能有點粗。
我感謝所有幫助, CK
ü可以創建一個http://fiddle.net這個 – dreamweiver