把下拉菜单的TEXT赋值给输入框-实例代码
来源:互联网 发布:pandora软件源 编辑:程序博客网 时间:2024/06/08 16:12
<script>$(document).ready(function() {$("#add").click(function(){$('#addForm').submit();});});//插入文本框方法 (function($) { $.fn.insertAtCaret = function (tagName) { return this.each(function(){ if (document.selection) { //IE support this.focus(); sel = document.selection.createRange(); sel.text = tagName; this.focus(); }else if (this.selectionStart || this.selectionStart == '0') { //MOZILLA/NETSCAPE support startPos = this.selectionStart; endPos = this.selectionEnd; scrollTop = this.scrollTop; this.value = this.value.substring(0, startPos) + tagName + this.value.substring(endPos,this.value.length); this.focus(); this.selectionStart = startPos + tagName.length; this.selectionEnd = startPos + tagName.length; this.scrollTop = scrollTop; } else { this.value += tagName; this.focus(); } }); }; })(jQuery);</script>
<sf:dictSelect dictCode="user.dict.code" name="tempPeople" /><input name="people" type="text" class="required" id="people" value="${projectname.people}" size="40" /><script>//将下拉菜单信息赋值给input function displayVals() { var checkText = $("#tempPeople").find("option:selected").text(); $('#people').insertAtCaret(checkText+" "); } $("#tempPeople").change(displayVals); displayVals();</script>