>

Ajax在线提交留言并实时突显的js代码[改良版]

- 编辑:乐百家599手机首页 -

Ajax在线提交留言并实时突显的js代码[改良版]

福寿无疆select组件的抉择输入过滤效果的js代码如下:

学学Ajax提交的心上人,无妨仿效一下吗,从中你会知晓一些本事吧。
因代码自个儿的难题,脚本之家已经纠正,应接我们测验。

复制代码 代码如下:

4:获得当选项options的text:

您恐怕感兴趣的篇章:

  • js实时获得并呈现当前时间的办法
  • Ajax在线提交留言并实时展现的js代码[修正版]
  • JS完毕的5级联合浮动Select下拉选拔框实例
  • js给selected添加options的方法
  • js完毕Select下拉框具备输入功效的格局
  • js完毕select跳转职能代码
  • js增加select下暗中同意的option的value和text的主意
  • js触发select onchange事件的小技能
  • js 触发select onchange事件代码
  • JS获取select的value和text值的简短实例
  • js自动查找select下拉的美食做法并选取(示例代码)
  • js达成Select头像挑选实时预览代码

姓名:

<tr>
          <td><?php echo $L_SpecialActivityIdentifier?></td>
          <td>
    <select name="Activity[Identifier]" id="Identifier" onchange="change_乐百家前段,activity(this.value)">
   <option value="">请选择</option>
   <?php
   foreach ($ActivityTypes as $Row ) {
    echo '<option value="'.$Row['Identifier'].'" '.($Row['Identifier']==$Activity['Identifier']?'selected':'').'>'.$Row['Name'].'</option>';
   }
   ?>
    </select>
     -- <input value='' id='to_find_str' size=16 style="text-align:center;" /><input value='find' onclick='find_select("Activity[Identifier]")' type=button />
          </td>
      </tr>

var vi = document.all['list'].length;
for(var i=0;i<vi;i  ){
  document.form2.list(i).value; //form2是<form>的名称
}
/**

*其中//******之间的部分显示的是在没有选择输入过滤功能的代码上加入的功能代码

**

/
/** 
* @description This plugin allows you to make a select box editable like a text box while keeping it's select-option features
* @description no stylesheets or images are required to run the plugin
*
* @version 0.0.1
* @author Martin Mende
* @license Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0)
* @license For comercial use please contact me: martin.mende(at)aristech.de
* 
* @requires jQuery 1.9 
*
* @class editableSelect
* @memberOf jQuery.fn
*
* @example
*
* var selectBox = $("select").editableSelect();
* selectBox.addOption("I am dynamically added");
*/

(function ( $ ) {

$.fn.editableSelect = function() {
var instanceVar;
//此this.each()指的就是对当前对象的遍历,这里的当前对象指代的就是对当前两个下拉选择框对象的一一遍历
this.each(function(){
var originalSelect = $(this);
//check if element is a select
if(originalSelect[0].tagName.toUpperCase()==="SELECT"){
//wrap the original select在原始的<select>外围插入<div></div>框
originalSelect.wrap($("<div/>"));
var wrapper = originalSelect.parent();
wrapper.css({display: "inline-block"});
//place an input which will represent the editable select
//在选择菜单上加入input输入框<input alt title ..... style="width:......" value="">
var inputSelect = $("<input/>").insertBefore(originalSelect);
//get and remove the original id
var objID = originalSelect.attr("id");
originalSelect.removeAttr("id");
//add the attributes from the original select
//input输入框的各种属性设置
inputSelect.attr({
alt: originalSelect.attr("alt"),
title: originalSelect.attr("title"),
class: originalSelect.attr("class"),
name: originalSelect.attr("name"),
disabled: originalSelect.attr("disabled"),
tabindex: originalSelect.attr("tabindex"),
id: objID
});
//get the editable css properties from the select
var rightPadding = 15;
inputSelect.css({
width: originalSelect.width()-rightPadding,
height: originalSelect.height(),
fontFamily: originalSelect.css("fontFamily"),
fontSize: originalSelect.css("fontSize"),
background: originalSelect.css("background"),
paddingRight: rightPadding
});
inputSelect.val(originalSelect.val());
//add the triangle at the right
var triangle = $("<div/>").css({
height: 0, width: 0,
borderLeft: "5px solid transparent",
borderRight: "5px solid transparent", 
borderTop: "7px solid #999",
position: "relative",
top: -(inputSelect.height()/2)-5,
left: inputSelect.width() rightPadding-10,
marginBottom: "-7px",
pointerEvents: "none"
}).insertAfter(inputSelect);
//create the selectable list that will appear when the input gets focus
//聚焦的时候加上<ol><ol/>下拉框
var selectList = $("<ol/>").css({
display: "none",
listStyleType: "none",
width: inputSelect.outerWidth()-2,
padding: 0,
margin: 0,
border: "solid 1px #ccc",
fontFamily: inputSelect.css("fontFamily"),
fontSize: inputSelect.css("fontSize"),
background: "#fff",
position: "absolute",
zIndex: 1000000
}).insertAfter(triangle);
//add options
//在resourceData变量中存储当前下拉框中的所有数据
//******
var resourceData = [];
originalSelect.children().each(function(index, value){
prepareOption($(value).text(), wrapper);
resourceData.push($(value).text());
});
//******
//bind the focus handler
//在鼠标聚焦的时候fadeIn(100),即下拉显示当前下拉框
inputSelect.focus(function(){
selectList.fadeIn(100);
//v存储的是在input输入框中输入的内容,如果输入的内容不为空,就在存储原始下拉框的所有数据中找到出现v中字符的数据压入newResourceData变量中
//******
var v = inputSelect.val();
var newResourceData = [];
if(v != "") {
$.each(resourceData, function(i, t){
if(t.indexOf(v) != -1)
newResourceData.push(t);
});
}
wrapper.children("ol").empty();
$.each(newResourceData, function(i, t){
prepareOption(t, wrapper);
});
//******
}).blur(function(){
selectList.fadeOut(100); 
}).keyup(function(e){
if(e.which==13) inputSelect.trigger("blur");
//在enter快捷键按下后弹起的时候执行的事件
//******
var v = inputSelect.val();
var newResourceData = [];
if(v != "") {
$.each(resourceData, function(i, t){
if(t.indexOf(v) != -1)
newResourceData.push(t);
});
}
wrapper.children("ol").empty();
$.each(newResourceData, function(i, t){
prepareOption(t, wrapper);
});
//******
});
//hide original element
originalSelect.css({visibility: "hidden", display: "none"});

//save this instance to return it
instanceVar = inputSelect
}else{
//not a select
return false;
}
});//-end each

/** public methods **/

/**
* Adds an option to the editable select
* @param {String} value - the options value
* @returns {void}
*/
instanceVar.addOption = function(value){
prepareOption(value, instanceVar.parent()); 
};

/**
* Removes a specific option from the editable select
* @param {String, Number} value - the value or the index to delete
* @returns {void}
*/
instanceVar.removeOption = function(value){
switch(typeof(value)){
case "number":
instanceVar.parent().children("ol").children(":nth(" value ")").remove();
break; 
case "string":
instanceVar.parent().children("ol").children().each(function(index, optionValue){
if($(optionValue).text()==value){
$(optionValue).remove();
}
});
break;
} 
};

/**
* Resets the select to it's original
* @returns {void}
*/
instanceVar.restoreSelect = function(){
var originalSelect = instanceVar.parent().children("select");
var objID = instanceVar.attr("id");
instanceVar.parent().before(originalSelect);
instanceVar.parent().remove();
originalSelect.css({visibility: "visible", display: "inline-block"});
originalSelect.attr({id: objID});
};

//return the instance
return instanceVar;
};

/** private methods **/
//prepareOption函数的作用就是在当前下拉框中添加新选项
function prepareOption(value, wrapper){
var selectOption = $("<li>" value "</li>").appendTo(wrapper.children("ol"));
var inputSelect = wrapper.children("input");
selectOption.css({
padding: "3px",
textAlign: "left",
cursor: "pointer" 
}).hover(
function(){
selectOption.css({backgroundColor: "#eee"});
},
function(){
selectOption.css({backgroundColor: "#fff"}); 
});
//bind click on this option
selectOption.click(function(){
inputSelect.val(selectOption.text());
inputSelect.trigger("change");
}); 
}

}( jQuery ));

显示留言

[Ctrl A 全选 注:如需引入外界Js需刷新才具进行]

function find_select(name)
{
 var select = document.getElementsByName(name);
 var find_str = document.getElementById('to_find_str').value;
 if(select)
 {
  select = select[0];
  var child = select.childNodes;
  var can=false,text='',len=child.length,is_end=true;
  for(var i=0;i<len;i )
  {
   if(can)
   {
    text = child[i].text;
    if( text &&
     text.indexOf(find_str)!=-1)
    {
     //console.log(text);
     child[i].selected = true;
     var v = child[i].value;
     select.value = v;
     select.onchange(v);
     is_end = false;
     break;
    }
   }
   if(child[i].selected)
    can = true;
  }
  if(is_end)
   alert('已未有相配内容');
 }
}

  1. 拿到select对象:

不要紧多付出三次留言试试看……

复制代码 代码如下:

代码:

Ajax留言本

你只怕感兴趣的文章:

  • asp select下拉菜单选取Logo并实时展现
  • input select(multiple) 完成下拉框输入值
  • select下拉摘取框美化达成代码(js css 图片)
  • jquery撤除选取select下拉框示例代码
  • 三个没有错的仿携程自定义数据下拉摘取select
  • js实现Select下拉框具有输入功效的法子
  • JS完结的5级联合浮动Select下拉摘取框实例
  • jQuery实现充裕实用美貌的select下拉菜单采用效果
  • 听他们讲jQuery完毕select下拉选拔可输入附源码下载
var myselect=document.getElementById("test");

您大概感兴趣的稿子:

  • js实时获得并展现当今日子的主意
  • JS达成的5级联合浮动Select下拉选用框实例
  • js给selected添加options的方法
  • js完结Select下拉框具有输入功用的不二秘技
  • js完结select跳转职能代码
  • js增多select下暗中认可的option的value和text的点子
  • js完结select组件的选择输入过滤代码
  • js触发select onchange事件的小手艺
  • js 触发select onchange事件代码
  • JS获取select的value和text值的简练实例
  • js自动查找select下拉的菜谱并精选(示例代码)
  • js完毕Select头像挑选实时预览代码

个别接纳javascript原生的不二等秘书诀和jquery方法

内容:

本文实例陈说了JS实现select选中option触发事件操作。分享给大家供大家参照他事他说加以考察,具体如下:

alert(options.val());

本次记住了吗应该

本文由乐百家前段发布,转载请注明来源:Ajax在线提交留言并实时突显的js代码[改良版]