1. 程式人生 > >把下拉選單的TEXT賦值給輸入框-例項程式碼

把下拉選單的TEXT賦值給輸入框-例項程式碼

<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>