如何在innerHTML中更改带有文本的img

时间:2016-10-31 09:30:04

标签: javascript html

这只是代码的一部分:

<div id="login">
    <form id="form" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']) ?>">
        <h1 id="heade">Register!</h1>
        <input type="text" id="username" name="username" placeholder="username (6-55char)" class="reqi">
        <input type="password" id="password" name="password" placeholder="password (6-55char)" class="reqi">
        <input type="password" id="passwordconfirmation" name="passwordconfirmation" placeholder="confirm password" class="reqi">
        <input type="text" id="email" name="email" placeholder="e-mail adress" class="reqi">
        <p id="req">Enter the Captcha code:</p>
        <h1 id="captcha"><img src="http://i.imgur.com/QgoRq4h.gif" alt="loading"></h1>
        <input type="text" id="code" name="code"><br>
        <div id="buttons">
            <input type="submit" id="submit">
            <button type="button" onclick="login()">Back to Log In</button>
        </div>
        <p><?php echo $txt; ?></p>
    </form>
</div>
<script>
    var captcha =<?php echo $_SESSION['final']; ?>;
    setTimeout(function () {
        document.getElementById("captcha").innerHTML = captcha;
    }, 3000);
    function login() {
        window.location = "main.php";
    }
</script>

等待3秒后,页面不会通过`id =&#34;验证码&#34;来改变h1中的图像。使用可变的验证码,顺便说一句,它不是空的(我检查过)。我需要一个javascript解决方案,因为我还不了解jQuery。提前谢谢!

2 个答案:

答案 0 :(得分:0)

它不是完整的代码片段。什么是$ _SESSION ['final']? 可能你在控制台中遇到javascript错误。

那一行:

.display {
    display: none !important;
}

产生语法错误,如:

var captcha=<?php echo $_SESSION['final']; ?>;

尝试将其更改为:

var captcha=XXXX;

答案 1 :(得分:0)

-(BOOL) checkIfFullAccessEnabled {
NSOperatingSystemVersion osv = [NSProcessInfo processInfo].operatingSystemVersion;
if(osv.majorVersion >= 10) {
    UIPasteboard *pb = [UIPasteboard generalPasteboard];
    if(pb.hasStrings || pb.hasURLs || pb.hasColors || pb.hasImages) {
        return YES;
    }
    else {
        NSString *ustr = pb.string;
        pb.string = @"777-TEST-123";
        if(pb.hasStrings) {
            pb.string = ustr;
            return YES;
        }
        else {
            return NO;
        }
    }
}
else if([UIPasteboard generalPasteboard] != nil) {
    return YES;
}
else {
    return NO;
}

}