我有两个js文件,一个用于汽车品牌,另一个用于用户位置。我创建了一个表单,并将它们都添加到同一html页面中。但是最终无法正常工作的js文件,而上面的js文件却没有。 是否有任何解决方案或方法可以在同一页面中使用两个js文件。因此它们都可以正常工作。 谢谢
function populatelocation(p1,c1){
var p1=document.getElementById(p1);
var c1=document.getElementById(c1);
c1.innerHTML="";
if (p1.value == "Azad Kashmir")
{
var optionArray = ["|Select Location",
"athmuqam|Athmuqam","bagh|Bagh","bhimber|Bhimber",
"forward Kahuta|Forward Kahuta"];
}
else if (p1.value == "Balochistan")
{
var optionArray = ["|Select Location",
"awaran|Awaran","barkhan|Barkhan","chagai|Chagai",
"dera Bugti|Dera Bugti","duki|Duki","gwadar|Gwadar","harnai|Harnai"];
}
for (var option in optionArray)
{
var pair = optionArray[option].split("|");
var newOption = document.createElement("option");
newOption.value=pair[0];
newOption.innerHTML=pair[1];
c1.options.add(newOption);
}
}
function popuulatebrand(b1,m1){
var b1=document.getElementById(b1);
var m1=document.getElementById(m1);
m1.innerHTML="";
if (b1.value == "Audi")
{
var optionArray = ['|Select Model
*',"A1|A1","A2|A2","TTS|TTS",'Other|Other'];
}
else if (b1.value == "BMW")
{
var optionArray = ["|Select Model","F06 06
SERIES|F06 06 SERIES","G02 X4|G02 X4",
"G29 Z4|G29 Z4","G20 3 SERIES|G20 3 SERIES",
"I01 I3|I01 I3","I12 I8|I12 I8",'Other|Other'];
}
else if (b1.value == "Other")
{
var optionArray = ['other|Other'];
}
for (var option in optionArray){
var pair = optionArray[option].split("|");
var newOption = document.createElement("option");
newOption.value=pair[0];
newOption.innerHTML=pair[1];
m1.options.add(newOption);
}
}
<script src="js/location.js" type="text/javascript"></script>
<script src="js/brandmodel.js" type="text/javascript"></script>
<body>
<div>
<select class="form-control " id="brand" name="brand" onchange="populatebrand(this.id,'model')">
<option value="">Choose...</option>
<option value="Audi" >Audi</option>
<option value="BMW" >BMW</option>
</select>
<select class="form-control" id="model">
<option value="" >Choose...</option>
</select>
</div>
<div>
<select class="form-control" name="province" id="province" onchange="populatelocation(this.id,'city')">
<option value="">Choose Province...</option>
<option value="Azad Kashmir">Azad kashmir</option>
<option value="Balochistan">Balochistan</option>
</select>
<select class="form-control" name="city" id="city">
<option>Choose Location...</option>
</select>
</div>
</body>
答案 0 :(得分:1)
首先,我可以在您的代码中看到一个简单的错误。您在函数定义的getController.deleteRec = function(req,res,collection){
var id = req.params.id;
console.log(id);
collection.findByIdAndUpdate({'subitem.messages._id': id}, {$pull:{'subitem.$.messages._id': id}}).
then(function(result){
console.log(result);
});
};
中有两个u。
修复此问题后,我测试了您的代码,然后收到以下错误(来自brandmodel.js脚本):
populatebrand
之所以发生此错误,是因为在定义SyntaxError: Invalid or unexpected token
时,您已经将某些字符串/元素拆分为新行。您应该在同一行上完成字符串。
您的代码如下:
optionArray
通过这些更正,您的功能将如下所示:
var optionArray = ['|Select Model
*',"A1|A1","A2|A2","TTS|TTS",'Other|Other'];
我已经对这些更改进行了测试,并且现在可以识别两个脚本中的功能(即使它们位于单独的js文件中)。