为什么我的JavaScript函数只能工作一次?

时间:2016-03-22 10:42:56

标签: javascript php

<a href="javascript: codeChange()">

//write an img tag to the screen

<script>
// @para1 of verCode: numbers of the characters
// @para2 of verCode: the width of the picture
// @para3 of verCode: the height pf the picture
// the php code is from $code = verCode(),in which the function  verCode is generating some verification code.

var code = "<?=$code?>"
document.write("<img src='backend/verificationCode.php?code=" + code + "' id='codePic'>")

//when the a tag is clicked, the function below executes

function codeChange() {
  var code = "<?=verCode(4, 70, 20)?>"
  document.getElementById("codePic").src = "backend/verificationCode.php?code=" + code + "" 

//the url links to a php page to change the code into picture

}
</script>

</a>

奇怪的是,当我第一次点击图像(在a标签内)时,它发生了变化,但之后,它就没有了。我的代码出了什么问题?为什么会这样?

1 个答案:

答案 0 :(得分:1)

verCode(4, 70, 20);

似乎返回相同的值,即使图像正在改变。你没有注意到它。 希望它有所帮助:)