Onclick命令不会将ID发送到文本框,Onclick需要" escape "被识别为代码

Onclick command wont send ID to text box, onclick needs "escaping" to be recognized as code

本文关键字:Onclick quot 需要 escape 代码 识别 命令 ID 文本      更新时间:2023-09-26

你好,我希望我说的有意义,我正在做一项任务,但是我可以。我不记得如何转义一行代码,所以我需要的代码被视为代码?如果有意义的话。

我有这样一段:

<input type="text" name="firstSeat" id="firstSeat" readonly="readonly" style="border: solid; background-color: #374B5C; color: #fff; width:30px;"/>

这个框的ID是firstSeat,我想用A01这样的ID填充它,使用下面的代码;

编辑我有麻烦粘贴我的代码在这里,有些没有显示,所以我希望这些是OK的。

代码也在这里https://gist.github.com/7f54751e1563e778d482

在第10行和第13行,有这样的代码:
<%Do While Not thrus.EOF
 dim seatID
 seatID=thrus("sea_ID")
 bookedcheck="SELECT * FROM booking WHERE boo_PerID = " & request("per_ID") &" AND booking.boo_seaID = "& seatID&""
 booked.Open bookedcheck, conx, adOpenkeyset, AdLockOptimistic
 if (thrus("sea_Reference") = "B01") OR  (thrus("sea_Reference") = "C01") OR  (thrus("sea_Reference") = "D01") OR  (thrus("sea_Reference") = "E01")OR  (thrus("sea_Reference") = "F01")OR  (thrus("sea_Reference") = "G01")Then
    Response.write "<br />"
 end if
 if not booked.EOF then
    response.write("<href='#"&thrus("sea_Reference")&"'><img src='images/booked.gif' border='0' title='"&thrus("sea_Reference")&", SEAT BOOKED' onclick='document.getElementById('firstSeat').value='"&thrus("sea_Reference")&"';' /></>")
 else
    response.write("<a href='#"&thrus("sea_Reference")&"'><img src='images/"&thrus("sea_ICON")&"' border='0' title='"&thrus("sea_Reference")&", &pound;120,  45 degree left seating icon facing stage' onclick='document.getElementById('firstSeat').value='"&thrus("sea_Reference")&"';' /></a>")
end if%>

应该发生的是onclick它把sea_reference推到firstSeat并传递给上面那个方框。但是当我点击它时它不会发送它

我相信这是因为:https://i.stack.imgur.com/aGpkP.png

onclick被视为与该行大部分代码相同的信息。

我想我需要"escape",这样onclick命令才能被看到。

如果有人可以帮助,或者确实帮助我得到我的代码在这里!那太好了,谢谢。

更新如果它有助于看到页面;http://heweb.grimsby.ac.uk/STUDENT/s0191958/PART2/booking.asp?the_ID=1& per_ID = 1

我觉得你的代码使用了错误的引号导致中断,使用单引号表示字符串文字;在你的代码中,当你使用那些单引号时,你有效地关闭了文字,并在firstSeat之后开始另一个,把它们放在那里传递你的参数。使用双引号。

这是一个半途而废的答案,但也许会有所帮助。

用这个代替你有的,看看这是否能帮到你。

onclick='document.getElementById("firstSeat").value=thrus("sea_Reference")'

要更改元素id,只需:

onclick=document.getElementById('firstSeat').id="sea_Reference"

也可以改变元素的值,使用:

onclick=document.getElementById('sea_Reference').value="value"

作为id属性更改之前,您应该使用新的id来引用。

如果你有一个函数返回数据作为id或值作为字符串,你不必用双引号或单引号把它括起来。只需将值保存在变量中,并对变量进行格式化,然后将其分配给属性(在JS中)。或者,如果您在服务器端,则将变量连接到要打印的字符串。(服务器端语言)