2011-05-05 198 views
0

如何根據點擊的div的邊框寬度更改選擇框值。jQuery選擇框值

<select id="borderWidth"> 
    <option>none</option> 
    <option>1px</option> 
    <option>2px</option> 
    <option>3px</option> 
    <option>4px</option> 
    <option>5px</option> 
</select> 

<div style="border:1px solid #cccccc"></div> 
<div style="border:5px solid #cccccc"></div> 

http://jsfiddle.net/AjxTA/2/

回答

3

http://jsfiddle.net/F5Gms/

$('div').click(function() { 
    var x = $(this).css('border-top-width'); 
    $("#borderWidth").val(x); 
}) 
+0

或者只是'$( 「#邊框寬度」)VAL(X)':http://jsfiddle.net/fkling/t2ruM/1/ – 2011-05-05 22:36:23

+0

hehe yeah ..剛剛意識到那個;) – ariel 2011-05-05 22:37:25