窗口打开不能在JavaScript函数中工作

时间:2016-01-29 14:48:49

标签: javascript

我有这个正常工作的javascript功能,它允许我根据角色选择字段中选择的选项显示隐藏字段。在地址字段具有onchange事件后,var formgroup2 变量中的选择字段应该在创建新办公室时选择时打开模式窗口。当我将它添加到函数但不在其工作的函数之外时,此部分不起作用。

  function hide () {
  console.log("whatever")
  }
  function visibilite1(_this) {
 var formgroup1 = '<div id="test1" class="divs"><label>Name </label> <input type="text" name= "name" id= "name" required>  </br><label>User  name </label><input type="text" name= "username" id= "username"    required></br><label >Password <em>*</em></label><input   type="password"   name= "password" id= "password" required></br></div>'

var formgroup2 = '<div id="test2" class="divs"><label>Name </label<input type="text" name= "name" id= "name" required> </br><label>User  name </label><input type="text" name= "username" id= "username"   required> </br><label>Password <em>*</em></label><input type="password"  name= "password" id= "password" required> </br> <label>Adress<em>* </em></label><input type="text"   name= "adress" id= "adress" required></br>  <select name="office" id="office" onchange="goToPage()"  required> <option value="">select office </option> <?php   while($d=mysqli_fetch_array($req)) {echo"<option   value=".$d['OfficeName'].">".$d['OfficeName']."</option>";   }mysqli_free_result($req);  ?><option value="Create new office"   style="color:blue; font-weight:bold">create new office</option></select>
</div>'
var formtestElement = document.getElementById('formtest'); 
 if (_this.value == "test1") {
  formtestElement.innerHTML = formgroup1
} else if (_this.value == "test2") {
  formtestElement.innerHTML = formgroup2
};
}


<select name="role" id="role"onchange="visibilite1(this);hide()" >
<option value='test1'>Year1</option>
<option value='test2'>Year2</option>
</select>

<div id="formtest">
<div id="test1" class="divs">
<label>Name </label>
<input type="text" name="name" id="name" required>  </br>
<label>User name </label>
<input type="text" name="username" id="username" required></br>
<label>Password <em>*</em></label>
<input type="password" name="password" id="password" required></br>

   

1 个答案:

答案 0 :(得分:0)

EXPLAIN

您永远不会关闭<select name="office" id="office" onchange="var maVal = document.getElementById(" office ").value; if (maVal =="Create new office ") {window.open("newOfficeCreate.php ", "blank ", "scrollbars=yes, resizable=no, top=50, left=155, width=1200, height=700 ");"} required> 属性。

我想。这真的很难说。试图内联这样的东西真是太可怕了;编写一个函数,如果您认为必须使用属性,则引用它,或者稍后附加它。