0
新手jquery用戶在這裏。我正在尋找打開一個模式,當一個輸入被聚焦/選擇,並從模態中的按鈕輸入一個值的輸入。是否可以在輸入焦點上打開一個模態並從模態輸入一個值到輸入?
所以事件會。 1.聚焦輸入。 2.打開一個模式。 3.通過使用按鈕在輸入中輸入一個值。 4.關閉按鈕關閉模式。
非常感謝。
新手jquery用戶在這裏。我正在尋找打開一個模式,當一個輸入被聚焦/選擇,並從模態中的按鈕輸入一個值的輸入。是否可以在輸入焦點上打開一個模態並從模態輸入一個值到輸入?
所以事件會。 1.聚焦輸入。 2.打開一個模式。 3.通過使用按鈕在輸入中輸入一個值。 4.關閉按鈕關閉模式。
非常感謝。
你會想要麼prompt()
:
$('body').on('focus', 'input[name=myNameHere]', function(){
var input = prompt('The Question', 'Suggested answer');
$(this).val(input);
});
或通過jQuery UI更高級的對話。
這可能是你在找什麼:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script>
$(function() {
$("#dialog").dialog({modal: true, autoOpen:false});
$("#result").focus(function() {
$("#dialog").dialog("open");
});
$('#accept').click(function(){
$('#result').val($('#source').val());
$('#dialog').dialog("close");
});
});
</script>
</head>
<body>
<input type="text" id="result">
</div>
<div id="dialog" title="Basic dialog">
Enter value <input type="text" id="source" /><br/>
<input type="button" id="accept" value="OK" />
</div>
</body>
</html>
這是偉大的,和聲音完全可行的。但是,SO不是「爲我寫代碼」的服務,所以:[你嘗試過什麼?](http://mattgemmell.com/2008/12/08/what-have-you-tried/)。 –