标签: getelementbyid

通过Javascript继承CSS值

在我的页面上,我正在通过javascript更改一些CSS样式.当我尝试拉出一个已经继承的值时 - 它会显示为空白.考虑以下:

    .Sliding
    {
        display: none;
        overflow: hidden;
    }

    .Sliding #FilterBox
    {
        height: 185px;
        background-color: Fuchsia;
    }
Run Code Online (Sandbox Code Playgroud)

和HTML:

<div class="Sliding" id="FilterBox">
        <h3>Test Form</h3>
        This is a test/<br />
        12345
</div>
Run Code Online (Sandbox Code Playgroud)

如果我查看元素' document.getElementById(objname).style.display '它的空白?如何通过javascript读取显示值?

javascript css getelementbyid

9
推荐指数
1
解决办法
9054
查看次数

IE中的javascript:getElementById问题

我试图使用JavaScript将单击事件附加到复选框.下面显示的是HTML和JS.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <input type="hidden" name="caution_c" value="0">
        <input type="checkbox" id="caution_c" name="caution_c" value="1" tabindex="120">
        <script type="text/javascript">
            var cb = document.getElementById('caution_c');
            cb.onclick = function() {
                alert(1);
            }
        </script>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

问题是在IE中,click事件不会触发.我缩小了问题的位置.问题是复选框之前有一个隐藏的输入,这两个元素具有相同的名称.我不确定为什么这会导致问题(毕竟,我使用的是getElementById,而隐藏的元素甚至没有id).

这种行为是否有正当理由(仅适用于IE.在Firefox中正常工作......一如既往:()?还有一个很好的解决方法(我可以做document.getElementsByName('caution_c')[1]但我不想...)

html javascript internet-explorer getelementbyid

9
推荐指数
1
解决办法
2万
查看次数

document.getElementById('id').值在ASP.net javascript函数中失败

隐藏的字段:

<input type="hidden" id="hidOrg1"  runat="server" value="" />
<input type="hidden" id="hidBT" runat="server" value="" />
Run Code Online (Sandbox Code Playgroud)

javascript函数:

function doGetWave(obj) {
    //debugger
    var brk = document.getElementById('hidBT').value;
    //var brkId = document.getElementById('hidBI').value;
    var org = document.getElementById('hidOrg1').value;
    session = obj.options[obj.selectedIndex].value;
    sWaveText = obj.options[obj.selectedIndex].text;    
    if (brk == "") {
        window.location.href = "url.aspx?multiple=" + org + "&wave=" + sWaveText + "&strORGId=multiple";
    }
    else {
        window.location.href = "url.aspx?multiple=" + org + "&wave=" + sWaveText + "&BRKType=" + brk + "&strORGId=multiple";
    }
}
Run Code Online (Sandbox Code Playgroud)

代码隐藏:

protected void Page_Load(object sender, EventArgs e)
{ …
Run Code Online (Sandbox Code Playgroud)

javascript c# asp.net getelementbyid runatserver

9
推荐指数
1
解决办法
4万
查看次数

C#为什么方法HtmlDocument.GetElementById匹配标签的属性名称?

HtmlDocument.GetElementById("$id") 
Run Code Online (Sandbox Code Playgroud)

我想使用此方法来获取元素$id,但它匹配具有meta与其具有相同值的属性的标记$id.

HtmlDocument是这样的:

<html>
    <head>
        <meta name="description" content="">
    </head>
    <body>
        <div id="description"></div>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

我试图获取divid为"description"的标签:

HtmlElement elem = doc.GetElementById("description");
Run Code Online (Sandbox Code Playgroud)

但我得到了meta而不是div.为什么meta标签匹配?

c# dom getelementbyid

9
推荐指数
1
解决办法
1353
查看次数

getElementsByClass和appendChild

只是刷新我的JavaScript技巧,并试图找出为什么getElementsByClass不适用于我的代码.代码非常简单.单击"clicky"按钮后,脚本将创建div的子h1元素.当我使用getElementById并将div类更改为Id但在将其更改为class时不起作用时,它工作得很好.

我试过,getElementsByClassName,getElementsByClass,getElementsByTagName并将div更改为适当的属性但没有运气.

<!doctype html>
<html>


<body>
<p>Click on button to see how appendChild works</p>

<button onclick="myFunction()">Clicky </button>

<script>
function myFunction(){
var first = document.createElement("H1");
var text = document.createTextNode("Jason is pretty awesome");
first.appendChild(text);

document.getElementsByName("thistime").appendChild(first);

}
</script>

<div class="thistime">Hi</div>

    </body>






</html>
Run Code Online (Sandbox Code Playgroud)

javascript html5 getelementbyid appendchild css3

9
推荐指数
2
解决办法
2万
查看次数

为什么document.getElementById()函数存在?

在创建网页时,我总是使用功能

var someVariable = document.getElementById('myID');
Run Code Online (Sandbox Code Playgroud)

获取对元素对象的引用.最近有人向我建议这不是必要的,因为已经存在这样的变量.它的名字等于id.我测试过它似乎有效.

<div id="myID">some text</div>
<a href="someplace" onclick="alert(myID.innerHTML)">click here</a>
Run Code Online (Sandbox Code Playgroud)

此代码有效,它会按预期警告"某些文本".firefox错误控制台中只有一个警告:

全局范围内由ID/NAME引用的元素.使用WC3标准document.getElementById()代替....

我现在大部分时间都在使用jQuery,但我需要向工作中的老板证明一点,否则我将不得不给他买一盒巧克力:-).

任何想法为什么上层代码不起作用或为什么使用它是一个非常错误的想法(在Firefox中警告是不够的)???

谢谢你的回答

javascript getelementbyid

8
推荐指数
2
解决办法
2684
查看次数

document.getElementById()在IE9上返回null

我正在制作一个弹出窗口,我在使用Internet Explorer 9时遇到了一些困难.这是给我带来麻烦的一段代码:

var popUp= document.getElementById('projectInfo');
popUp.style.left=(tempX-310)+'px';
popUp.style.top=(tempY-110)+'px';
Run Code Online (Sandbox Code Playgroud)

在IE9中(尚未在先前版本中测试),弹出窗口为空.在adition中,我尝试在正文结束标记之前包含我的.js文件,并将我的函数包装在"document.ready()"函数中,但这些都不起作用.相同的代码虽然在Opera,Chrome和Firefox中完美运行.有谁知道发生了什么?

注意:该函数在我的html的body的onLoad属性中调用.

javascript internet-explorer getelementbyid

8
推荐指数
1
解决办法
1万
查看次数

使用getElementById使用javascript更改CSS

我不知道如何使用javascript访问特定的CSS.

让我们说,

#menu { color: red; }
Run Code Online (Sandbox Code Playgroud)

可以访问

document.getElementById('menu').style.color = "blue";
Run Code Online (Sandbox Code Playgroud)

但我想访问

#menu li a { height: 10%; }
Run Code Online (Sandbox Code Playgroud)

如何使用document.getElementById()访问它?

html javascript css getelementbyid

8
推荐指数
1
解决办法
3万
查看次数

DOM getElementbyId无法正常工作

从HTML表单中提取输入值时遇到一些问题.据我所知,我的代码没有任何问题,但我找不到问题所在.

<?php
error_reporting(E_ALL );
    ini_set('display_errors', 1);

$t =<<<D
<form id="frm-send" method="post"   action="index.php"   >
<input type="text" name="data[postusername]" id="postusername" value="user"  />    
<input type="checkbox"  name="data[save]" id="data[save]" value="1" />   
<input type="hidden" name="secret" id="secret" value="0d35635c0cb11760789de6c4fe35e046311f724b" />
<input type="submit" name="btnSubmit" id="btnSubmit" value="Send"  />   
<input type="hidden" name="data[checkgetrequest]" value="true" id="data[checkgetrequest]" />
<input type="hidden" name="frm-id" value="13448477965028bfb44222d" id="frm-id" />
</form>
<input type="text" id="getfocus_txt_13448477965028bfb44222d" name="getfocus_txt_13448477965028bfb44222d" />


D;
    $dom = new domDocument;
    $dom->loadHTML($t);
    $dom->preserveWhiteSpace = true;
    $frmid = $dom->getElementById('frm-id') ;
    echo  $frmid->getAttribute('value');


?>
Run Code Online (Sandbox Code Playgroud)

它显示了一个错误:

Fatal error: Call to a member function getAttribute() …
Run Code Online (Sandbox Code Playgroud)

php xampp dom getelementbyid

8
推荐指数
2
解决办法
3380
查看次数

Ionic2/Angular2/TypeScript:如何访问函数2016中的DOM元素

我似乎找不到以正确方式访问DOM元素的"正确"方法:
Angular2 + Ionic2 + TypeScript.

所以鉴于以下情况......

问)如何sketchElement在sign()函数中访问?

Settings.ts模板:

<button full class="top-button-margin" (click)="sign()">
  Sign
  <ion-icon name="create"></ion-icon>
</button>
<img id="sketchElement" src="img/logo.png" padding *ngIf="showSignatureView">
Run Code Online (Sandbox Code Playgroud)

我的settings.ts类:

@Page({
  templateUrl: 'build/pages/settings/settings.html'
})
export class SettingsPage {

  private currentUser: User = <User>{};
  private loggingOut: boolean = false;
  private currentConnection: string = "";
  private showSignatureView: boolean = false;

  constructor(
    private _platform: Platform,
    private _nav: NavController,
    private _events: Events,
    private _LoginService: LoginService,
    private _SessionService: SessionService,
    private _UIService: UIService) {

  }

  sign() {
    // I want to …
Run Code Online (Sandbox Code Playgroud)

getelementbyid typescript ionic2 angular

8
推荐指数
1
解决办法
2万
查看次数