尝试将变量与联系人详细信息连接起来。

时间:2015-03-06 07:46:01

标签: javascript html concatenation

有人可以帮助我解决这个问题吗,我正在努力实现一个下拉选择按钮,显示一旦点击的课程的相关提供者,但是大多数课程有多个提供者(6-8)

我让所有提供者都通过变量,当我尝试连接时,它会导致空白。

有人可以帮忙,非常感谢。

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
</head>

<body>
<label for="programSelect">  Please choose a Programme<br><br></label>
<select id="nearestStore">
  <option value="noSelection">Please Select</option>
  <option value="StudyP">Study Programmes</option>
  <option value="Train">Traineeships</option>
  <option value="Acc">Accountancy</option>
  <option value="Agri">Agricultural and Land Based</option>
  <option value="Anim">Animal Care</option>
  <option value="Beauty">Beauty Therapy</option>
  <option value="Busin">Business Improvement Tech</option>
  <option value="Busina">Business Administration</option>
  <option value="CallC">Call Centres</option>
  <option value="Creative">Creative arts</option>
  <option value="Construct">Construction</option>
  <option value="Customer">Customer service</option>
  <option value="Cyber">Cyber Security</option>
  <option value="Early">Early years ChildCare & Education</option>
  <option value="Electro">ElectroTechnical</option>
  <option value="Electric">Electricity Industry</option>
</select>



 <div id="phoneNumber"></div>

 <script>
  var nearestStore = document.getElementById("nearestStore"),
      phoneNumber = document.getElementById("phoneNumber"),

      contactdetails = {
        noSelection: "",
        StudyP: "<br><a href='http://www.howcollege.ac.uk'>Heart of         Worcestershire College</a><br>Emily Leleu<br>01905 743587<br>",

        Train: "<br><a href='http://www.howcollege.ac.uk'>Heart of Worcestershire College</a><br>Emily Leleu<br>01905 743587",


    }

   nearestStore.onchange = function(){
    phoneNumber.innerHTML = contactdetails[this.value];
    contactdetails.StudyP: += '<a     href='http://www.warwickshire.ac.uk/colleges/henley-in-arden.aspx'>Henley in           Arden College</a><br>Personname<br>number<br><br>';

    }



</script>

1 个答案:

答案 0 :(得分:0)

你形成一个字符串的方式是错误的,它与单引号(&#39;&#39;)和双引号(&#34;&#34;)有关。而且,你有一个冒号(:)。修改后的行是

contactdetails.StudyP += "<a href='http://www.warwickshire.ac.uk/colleges/henley-in-arden.aspx'>Henley in Arden College</a><br>Personname<br>number<br><br>";

用这个替换你的行。