<script language="javascript">
function hello()
{
var selectproducto = document.getElementById("producto");
var totalproducto = document.getElementById("producto").length;
var selectmanufacturero = document.getElementById("manufacturero");
var chosenoption = selectmanufacturero.options[selectmanufacturero.selectedIndex].getAttribute('value');
var limite = totalproducto;
for(var i = 0; i<limite; i++) {
if(i==0){ alert('|'); }
else if(i==7){ alert('|'); }
else{
var ahora = selectproducto.options[i].getAttribute('title');
alert(i);
if(ahora == chosenoption){ alert('+'); }
else{
alert('-');
selectproducto.options[i] = null; //saca la opcion
}
}
}
selectproducto.style.display = 'block';
}
</script>
<script language="javascript" type="text/javascript">
function addm()
{
document.getElementById("manufacturero").style.display="none";
document.getElementById("new_man").style.display="block";
document.getElementById("new_product").style.display="block";
}
</script>
<script language="javascript" type="text/javascript">
function addp()
{
document.getElementById("producto").style.display="none";
document.getElementById("new_product").style.display="block";
}
</script>
<?php
// ---------------- Crea opciones a escoger para los manufactureros -----------
$query = "SELECT * FROM manufactureros";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
$anterior = $manufactureros;
$manufactureros = $anterior."<option id='manufacturero_opcion' value='".$row['name']."'>".$row['name']."</option>";
}
// ---------------- Crea opciones a escoger para los articulos ----------------
$result = mysql_query("SELECT * FROM productos");
while($row = mysql_fetch_assoc($result))
{
$anterior = $productos;
$productos = $anterior."<option value='".$row['descripcion']."' title='".$row['manufacturero']."'>".$row['descripcion']."</option>";
}
?>
</head>
<body>
<form id="reservacion" action="#" method="POST" style="display:block;">
<div><b>Artículo</b><br />
<select id="manufacturero" name="manufacturero" style="display:block;margin-left:20px" onchange='hello()'>
<option value="FALSE" selected="selected">- Elige el manufacturero -</option>
<?=$manufactureros?>
<option value="FALSE" onClick="addm()">..Añadir manufacturero..</option>
</select><br />
<div id="new_man" style="display:none;margin-left:20px; margin-top:-20px; margin-bottom:-20px">Reservar con un manufacturero nuevo:<br />
<input type="text" name="new_man" size=40 value="" style="margin-left:20px; margin-top:10px">
</div>
<select id="producto" name="producto" style="display:block;margin-left:20px; margin-top:-14px">
<option value="FALSE" selected="selected">- Elige el artículo -</option>
<?=$productos?>
<option value="FALSE" onClick="addp()">..Añadir producto..</option>
</select><br />
<div id="new_product" style="display:none; margin-left:20px; margin-bottom:20px">Reservar con un producto nuevo:
<table style="margin-left:20px">
<tr><td>Id : </td><td><input type="text" name="new_product_id" size=40 value=""></td></tr>
<tr><td>Descripción : </td><td><input type="text" name="new_product" size=40 value=""></td></tr>
</table>
</div>
</div>
<input type="submit" name="submit" value="Reserva">
</form>
</body>
0
A
回答
4
因为
document.getElementById("producto").length
== 5
通过对事物的外观:
<select id="producto" name="producto" style="display:block;margin-left:20px; margin-top:-14px">
<option value="FALSE" selected="selected">- Elige el artículo -</option>
<?=$productos?>
<option value="FALSE" onClick="addp()">..Añadir producto..</option>
</select><br />
的结果很可能是 “假” - 它的长度为5.
2
它看起来像你想迭代sele的选项克拉。您需要引用该属性。请注意,您只需检索它就不需要再次使用getElementById。
var totalproductos = selectproducto.options.length;
+0
这是正确的感谢! – Glorialis 2010-06-19 15:21:07
相关问题
- 1. 为什么我的for循环在一次迭代后停止?
- 2. 第一次“for循环”在第一次迭代后停止python
- 3. Java - for循环在一次迭代后停止
- 4. Python for循环在第一次迭代后停止
- 5. PHP for循环在第一次迭代后停止
- 6. Python for循环在第一次迭代后停止工作
- 7. 我的Javascript循环在1次迭代后停止
- 8. 循环停止在第一次迭代
- 9. 循环在一次迭代后停止所有代码
- 10. 嵌套for循环迭代停止
- 11. For循环在第一次迭代后终止-Excel VBA
- 12. while循环在1次迭代后停止[BASH]
- 13. 为什么在第一次迭代后停止?
- 14. for循环一次迭代后坠毁
- 15. for循环后1迭代
- 16. 循环迭代函数x次循环
- 17. For循环停止1循环后
- 18. 经过一次正确的迭代后停止内循环
- 19. 为什么我的代码在secound while循环中停止?
- 20. 暂停for循环的迭代?
- 21. 为什么我的python进程在几次迭代之后停止?
- 22. 为什么不能在我的代码中停止循环?
- 23. 第一次迭代后循环停止的Javascript
- 24. 我怎样才能停止从循环console.log每次迭代?
- 25. 为什么我的循环在数字为0时停止?
- 26. 为什么我的循环变量在1次迭代后没有活动?
- 27. 我如何知道for循环的最后一次迭代?
- 28. 第一次迭代循环后执行停止
- 29. 保存for循环的每次迭代
- 30. For循环停止在列表框中的第一项之后迭代
我们将看到一些html我认为。 – thomasfedb 2010-06-19 14:34:05
'script'元素的'language'属性[已弃用](http://www.w3.org/TR/html401/interact/scripts.html#h-18.2.1)。 – 2010-06-19 14:59:07