<!
DOCTYPE
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns="http://www.w3.org/1999/xhtml" xml:lang="yue-Hans" lang="yue-Hans">
<
head
>
<
meta
http-equiv="Content-Type" content="text/html; charset=gbk" />
<
title
>it works..............</
title
>
</
head
>
<
body
>
<
form
action="./" method="get">
<
dl
>
<
dt
>发布者</
dt
>
<
dd
>
<
select
name="q_role" onchange="role_change_type();">
<
option
value="company">中介</
option
>
<
option
value="person">个人</
option
>
</
select
>
<
select
name="q_type">
<
option
value="sale">出售</
option
>
<
option
value="lease">出租</
option
>
<
option
value="buy" style="display:none">求购</
option
>
<
option
value="hire" style="display:none">求租</
option
>
</
select
>
</
dd
>
</
dl
>
</
form
>
</
body
>
</
html
>
想实现一个很简单的功能:当选中“中介”时,不显示“求购”与“求租”。本以为通过display:none即可实现,结果发现在option元素上使用display:none在firefox中有效,在IE6、IE7、IE8中都无效。
所以,通过javascript设置display:none也是在IE中无效,代码如下:
<!
DOCTYPE
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns="http://www.w3.org/1999/xhtml" xml:lang="yue-Hans" lang="yue-Hans">
<
head
>
<
meta
http-equiv="Content-Type" content="text/html; charset=gbk" />
<
title
>it works..............</
title
>
</
head
>
<
body
>
<
form
action="./" method="get">
<
dl
>
<
dt
>发布者</
dt
>
<
dd
>
<
select
name="q_role" onchange="role_change_type();">
<
option
value="company">中介</
option
>
<
option
value="person">个人</
option
>
</
select
>
<
select
name="q_type">
<
option
value="sale">出售</
option
>
<
option
value="lease">出租</
option
>
<
option
value="buy">求购</
option
>
<
option
value="hire">求租</
option
>
</
select
>
</
dd
>
</
dl
>
<
script
type="text/javascript">
function role_change_type()
{
var q_role=document.getElementsByName("q_role");
var q_type=document.getElementsByName("q_type");
var q_type_option=q_type[0].getElementsByTagName("option");
if(q_role[0].value=='company')
{
if(q_type[0].value=='buy'||q_type[0].value=='hire')
{
q_type[0].value='sale';
}
for(var i=0;i!=q_type_option.length;i++)
{
if(q_type_option[i].value=="buy"||q_type_option[i].value=="hire")
{
q_type_option[i].style.display="none";
}
}
}
if(q_role[0].value=='person')
{
for(var i=0;i!=q_type_option.length;i++)
{
q_type_option[i].style.display="";
}
}
}
role_change_type();
</
script
>
</
form
>
</
body
>
</
html
>
所以,只能通过select元素的remove和add方法,当选中“中介” 时,把“求租”和“求购”删除。代码如下:
<!
DOCTYPE
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns="http://www.w3.org/1999/xhtml" xml:lang="yue-Hans" lang="yue-Hans">
<
head
>
<
meta
http-equiv="Content-Type" content="text/html; charset=gbk" />
<
title
>it works..............</
title
>
</
head
>
<
body
>
<
form
action="./" method="get">
<
dl
>
<
dt
>发布者</
dt
>
<
dd
>
<
select
name="q_role" onchange="role_change_type();">
<
option
value="company">中介</
option
>
<
option
value="person">个人</
option
>
</
select
>
<
select
name="q_type">
<
option
value="sale">出售</
option
>
<
option
value="lease">出租</
option
>
<
option
value="buy">求购</
option
>
<
option
value="hire">求租</
option
>
</
select
>
</
dd
>
</
dl
>
<
script
type="text/javascript">
var q_role=document.getElementsByName("q_role");
var q_type=document.getElementsByName("q_type");
var q_type_option=q_type[0].getElementsByTagName("option");
alert(q_role[0].value)
if(q_role[0].value=='company')
{
q_type[0].remove(3)
q_type[0].remove(2)
}
function role_change_type()
{
if(q_role[0].value=='company')
{
q_type[0].remove(3)
q_type[0].remove(2)
}
if(q_role[0].value=='person')
{
var x=document.createElement('option');
x.text='求购';
x.value='buy';
var y=document.createElement('option');
y.text='求租';
y.value='hire';
try
{
q_type[0].add(x,null);
q_type[0].add(y,null); // standards compliant
}
catch(ex)
{
q_type[0].add(x);
q_type[0].add(y); // IE only
}
}
}
</
script
>
</
form
>
</
body
>
</
html
>
这样在IE和firefox中都有效了。真费解啊,IE8竟然还不支持option的display:none 。
上面的代码还有一个问题:在IE7和IE8中 选中“个人”,然后刷新,将导致“求租”和“求购”被删除。在IE6和firefox3.5.5中正常。
标签: javascript, css, ie
相关推荐
* Add an option for choose input text or textarea for old tags field * Add an option for min chars autocompletion * Version 2.0-beta8 : * Update POT. * Update french translation. * Version 2.0-...
o Added 'Add Header Line To CSV/Tab-Delimited File' option. When this option is turned on, the column names are added as the first line when you export to csv or tab-delimited file. * Version 1.82...
this.options.add(NewOption, idx); NewOption.innerText = innerText; NewOption.value = value; if (!this.bOriginalSelect) this.createOptionTr(idx); this.syncOptions(); this.adjustOptionsDiv(); ...
Issue 11137: Remove the gerrit.reportBugText configuration option. This option was only used in GWT, which has been removed. Upgrade JGit to 5.3.5.201909031855-r. This version includes a fix for ...
当列头的hyperlink被点击的时候后,它将会传递GridView的名字,列的索引和列名给HideCol方法,这个方法能找到这一列的每个单元格,每个单元格的将添加display:none样式,用来隐藏这一列. 当选择"Show Column"中的...
- NEW: Add multi-display support. - NEW: Add API DynamicFont(name, font). - IMPROVED: Compatibility with 2018.3. - FIXED: Incorrect letter spacing on mobile platform. - FIXED: Same transition hook may...
* 那么如果存在时就加不上去(数量),如果不存在时(如果不存在时的数量不一样时)就insert上去 * */ $province = M('prvices')->where ( array('pid'=>1) )->select (); $this->assign('province',$...
o Added option to choose the file size display unit: Bytes, KB, or MB. * Version 2.50 o OutlookAttachView now remembers that last 20 strings you typed in the Extensions List, Excluded Extensions ...
Removes all the evaluation marks on a PDF file that was added by Foxit PDF Editor 2.1 all at once by selecting "Remove Evaluation Marks" under the Help menu for registered users. 5. Alignment Support...
b) if "Save archive name" and "Add to context menu" options were set in compression profile parameters and profile was invoked from Explorer context menu, WinRAR proposed an automatically ...
- Added write protect option for floppy drives. - Bugfixes / improved internal debugger + instrumentation. Detailed change log : - CPU and internal debugger - Implemented Process Context ID (PCID) ...
LSIP200245968 (DFCT) In EFICLI not able to flash latest firmware to controller without using -nosigchk -noverchk option. LSIP200233079 (DFCT) Redesign battery changes LSIP200232955 (DFCT) Porting ...
to add the Microsoft TCP/IP-32 drivers by following the instructions given in the documentation. Known Problems -------------- There have been a number of reports on IBM TokenRing, EtherLink III ...
Remove the incorrect use of SPI in LCD display, add a new schedule( maily used SPI busy flag ). 2. Commen off code "assert_param(IS_SPI_ALL_PERIPH(SPIx));" in "SPI_I2S_SendData()", ...
* Added CVS commands "Add" and "Remove" * Added configuration option for "Templates Directory" in "Environment Options" * Code-completion updates * Bug fixes Version 4.9.6.6 * Editor colors are ...
Remove the sidebar Google Checkout button 186 Summary 187 Chapter 9: Deploy, Secure, and Maintain Your Shop 189 Getting ready to deploy 189 Necessary WordPress adjustments 190 Your WordPress ...
-alpha option activate, deactivate, reset, or set the alpha channel -antialias remove pixel-aliasing -authenticate password decipher image with this password -attenuate value lessen (or intensify...
第1章 活动目录库套书的使用 1.1 活动目录库套书的组成 1.2 活动目录库套书的编写思想 第2章 本书的内容 2.1 组策略编程 第3章 微软参考资源 3.1 微软开发者网络 3.1.1 MSDN和MSDN在线的比较 3.1.2 订阅MSDN...