关闭→
当前位置:知科普>综合知识>js函数怎么写

js函数怎么写

知科普 人气:9.46K
1. 这个js函数该怎么写

我不理解你这句话:取出后连接上本次所点击的select索引的值, 最后从新赋值给select

js函数怎么写

如果是点击下拉值取得select中的值可以这样写:

给下拉框设个id="s1";

function selectt()

{

var a= document.getElementById("s1").options[document.getElementById("s1").options.selectedIndex].value;

//这里a就是你要取得的选中值

}

下拉框事件:onchanged="selectt()"

这样可以

var p="" function ge() { p=document.getElementById("s1").value ; // alert (a); } function selectt()

{

var a= p+document.getElementById("s1").options[document.getElementById("s1").options.selectedIndex].value;

//这里a就是你要取得的选中值 alert (a);

}

<select name="test1" id="s1" onclick="ge()" onchange ="selectt()" >

但单击时取得当前值,变换时取得选中值,串在一起,你试试效果

2. JavaScript函数写法

简单的例子,仅供参考:<script> function myFunction() //定义函数名 myFucntion { alert("Hello World!"); //函数内容要执行的代码块 }</script><body> //点击按钮触发函数。

3. 请教一个js函数写法

<table id="a"> <;!--设一个ID.让JS知道要在什么地方插入.-->

<tr>

<td onclick="insertTr()">a</td>

<td>b</td>

</tr>

</table>

<script type="text/javascript">

function insertTr() {

var name = document.getElementById('a');

var row, cell, txtNode;

row = document.createElement("tr");

cell = document.createElement("td");

var newText = document.createTextNode("插入行");

cell.appendChild(newText); //在td中插入的字符

row.appendChild(cell); //在tr中插入td

name.appendChild(row); //在table中插入tr

}

</script>

TAG标签:#函数 #js #