用JavaScript怎么改变输入框的属性

piziyelang 2011-11-01 03:44:04
有一个输入框

<input type="text" name="sKeyword" maxlength="80" style="width:350px;">

点击一个按钮的时候,想把输入框的属性 style="width:350px;" 改为 style="width:200px;"

应该怎么实现

谢谢了
...全文
108 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
三石-gary 2011-11-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 maderic 的回复:]
加个id
<input id="sKeyword" type="text" name="sKeyword" maxlength="80" style="width:350px;">

<input id="btn" type="button" value="Button" onclick="ChangeStyle()" />

function ChangeStyle(){
d……
[/Quote]
+1
piziyelang 2011-11-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 maderic 的回复:]
加个id
<input id="sKeyword" type="text" name="sKeyword" maxlength="80" style="width:350px;">

<input id="btn" type="button" value="Button" onclick="ChangeStyle()" />

function ChangeStyle(){
doc……
[/Quote]


搞定了,再次感谢
Legend1988 2011-11-01
  • 打赏
  • 举报
回复
+1[Quote=引用 3 楼 hookee 的回复:]

HTML code

<input type="text" name="sKeyword" maxlength="80" style="width:350px;">
<input type="button" value="click" onclick="document.getElementsByName('sKeyword')[0].style.width='200px';">
[/Quote]
hookee 2011-11-01
  • 打赏
  • 举报
回复

<input type="text" name="sKeyword" maxlength="80" style="width:350px;">
<input type="button" value="click" onclick="document.getElementsByName('sKeyword')[0].style.width='200px';">
光曰不日 2011-11-01
  • 打赏
  • 举报
回复
这个。。。
MadEric 2011-11-01
  • 打赏
  • 举报
回复
加个id
<input id="sKeyword" type="text" name="sKeyword" maxlength="80" style="width:350px;">

<input id="btn" type="button" value="Button" onclick="ChangeStyle()" />

function ChangeStyle(){
document.getElementById("sKeyword").style.width = "200px";
}

87,989

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧