0
div의 높이/너비를 변경하려면 다음 코드가 있지만 작동하지 않습니다. 아래의 경고 메시지는 빈 값만 인쇄합니다.javascript 동적으로 너비가 변경되지 않습니다.
<script>
function showmyidlist() {
try {
var myid = document.getElementById('myid');
var myidlist = document.getElementById('myidlist');
var divinput = myid.getElementsByTagName("input")[0];
alert(divinput.style.height + ":" + divinput.style.height);
myid.style.width = divinput.style.width;
myid.style.height = divinput.style.height;
alert(myid.style.width + ":" + divinput.style.width);
if (myidlist.style.position != 'absolute') {
myid.appendChild(myidlist);
myid.style.position = 'relative';
myidlist.style.position = 'absolute';
myidlist.style.top = '10px';
myidlist.style.left = '0px';
myidlist.style.zindex = 1;
myidlist.style.display = 'block';
} else if (myidlist.style.position == 'absolute') {
myidlist.style.position = '';
myidlist.style.zindex = 0;
myidlist.style.display = 'none';
myid.style.position = '';
}
} catch (e) {
alert(e);
}
}
</script>
<table>
<tr>
<td style="padding:0px 10px 0px 0px;text-align:right;width:20%;">Name</td>
<td style="padding:0px 0px 0px 0px;text-align:center;width:60%;">
<div id="myid"><input type="text" name="myid" value="" onclick="showmyidlist()"></div>
</td>
<td style="padding:0px 0px 0px 10px;text-align:left;width:20%;">
<input style="width:200px;" type="submit" class="button" name="submit" value="Add My Id" />
</td>
</tr>
</table>
<div id="myidlist" style="display:none;"></div>
그것은 undefinded를 말한다 : 정의되지 않음 – user1241438
죄송합니다, 내 게시물에 실수를했습니다. 지금 업데이트했습니다. 제 편집을 시도해보십시오. – aaroncatlin
이제 값을 인쇄하지만 값을 변경하면 작동하지 않습니다. myid.style.width = divinput.clientWidth; // 작동하지 않습니다. myid.clientWidth = divinput.style.width; // does not work – user1241438