我有一个帮助页面,help.php,我加载一个iframe里面main.php我怎样才能得到这个页面的高度,一旦它在iframe中加载?
我问这个是因为我无法将iframe的高度设置为100%或auto.这就是为什么我认为我需要使用javascript ..我正在使用jQuery
CSS:
body {
margin: 0;
padding: 0;
}
.container {
width: 900px;
height: 100%;
margin: 0 auto;
background: silver;
}
.help-div {
display: none;
width: 850px;
height: 100%;
position: absolute;
top: 100px;
background: orange;
}
#help-frame {
width: 100%;
height: auto;
margin:0;
padding:0;
}
Run Code Online (Sandbox Code Playgroud)
JS:
$(document).ready(function () {
$("a.open-help").click(function () {
$(".help-div").show();
return false;
})
})
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class='container'>
<!-- -->
<div class='help-div'>
<p>This is a div with an iframe loading the help page</p>
<iframe id="help-frame" src="../help.php" …
Run Code Online (Sandbox Code Playgroud) 在Javascript中,我似乎找不到将负数设置为零的方法?
-90变为0
-45变为0
0变为0
90变为90
有什么相似的吗?我只是四舍五入的数字.
我可以使用Javascript访问PHP var,如下所示:
<?php
$fruit = "apple";
$color = "red";
?>
<script type="text/javascript">
alert("fruit: " + "<?php echo $fruit; ?>"); // or shortcut "<?= $fruit ?>"
</script>
Run Code Online (Sandbox Code Playgroud)
但是如果我想使用外部JS文件怎么办:
<script type="text/javascript" src="externaljs.js"></script>
Run Code Online (Sandbox Code Playgroud)
externaljs.js:
alert("color: " + "<?php echo $color; ?>");
Run Code Online (Sandbox Code Playgroud) 我使用PHP的EOF字符串来格式化HTML内容,而不必担心必须转义引号等.如何在此字符串中使用该函数?
<?php
$str = <<<EOF
<p>Hello</p>
<p><?= _("World"); ?></p>
EOF;
echo $str;
?>
Run Code Online (Sandbox Code Playgroud) 我想在函数中声明多个变量:
function foo() {
var src_arr = new Array();
var caption_arr = new Array();
var fav_arr = new Array();
var hidden_arr = new Array();
}
Run Code Online (Sandbox Code Playgroud)
这是正确的方法吗?
var src_arr = caption_arr = fav_arr = hidden_arr = new Array();
Run Code Online (Sandbox Code Playgroud) 是否有一个更简单的功能:
if (isset($_POST['Submit'])) {
if ($_POST['login'] == "" || $_POST['password'] == "" || $_POST['confirm'] == "" || $_POST['name'] == "" || $_POST['phone'] == "" || $_POST['email'] == "") {
echo "error: all fields are required";
} else {
echo "proceed...";
}
}
Run Code Online (Sandbox Code Playgroud) 我找到了两个使用Javascript获取cookie数据的函数,一个在w3schools.com上,一个在quirksmode.org上
我想知道我应该使用哪一个?
例如,我相信我在某处看到某些浏览器分裂;
分号存在问题?
W3Schools的:
function getCookie(c_name) {
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + "=");
if (c_start != -1) {
c_start = c_start + c_name.length + 1;
c_end = document.cookie.indexOf(";", c_start);
if (c_end == -1) c_end = document.cookie.length;
return unescape(document.cookie.substring(c_start, c_end));
}
}
return "";
}
Run Code Online (Sandbox Code Playgroud)
怪异模式:
function readCokie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i]; …
Run Code Online (Sandbox Code Playgroud) 好的,我有列表项,有些有跨度,有些没有.
在我的活动中,我想在他们还没有时添加跨度.
has()
工作得很好,但not()
两者都增加了跨度?
HTML:
<ul>
<li>
<p>item</p>
<span class="spn">empty span</span>
</li>
<li>
<p>item 2</p>
</li>
<ul>
<hr>
<a class="add-span"href="#">check</a>
Run Code Online (Sandbox Code Playgroud)
JS:
$("a.add-span").click(function() {
$("li").each(function(index) {
// $(this).has("span").find("span").append(" - appended");
$(this).not("span").append('<span class="spn">new span<\/span>');
})
})
Run Code Online (Sandbox Code Playgroud) $ser = 'a:2:{i:0;s:5:"héllö";i:1;s:5:"wörld";}'; // fails
$ser2 = 'a:2:{i:0;s:5:"hello";i:1;s:5:"world";}'; // works
$out = unserialize($ser);
$out2 = unserialize($ser2);
print_r($out);
print_r($out2);
echo "<hr>";
Run Code Online (Sandbox Code Playgroud)
但为什么?
我应该在序列化之前进行编码吗?怎么样?
我使用Javascript将序列化字符串写入隐藏字段,而不是PHP的$ _POST
在JS中我有类似的东西:
function writeImgData() {
var caption_arr = new Array();
$('.album img').each(function(index) {
caption_arr.push($(this).attr('alt'));
});
$("#hidden-field").attr("value", serializeArray(caption_arr));
};
Run Code Online (Sandbox Code Playgroud) 我有一个动态列表,需要选择前一项.
<ul class="album">
<li id='li-1'></li>
<!-- ... -->
<li id='li-8'></li>
<li id='li-9'></li>
<li class='drop-placeholder'>drag your favorites here</li>
</ul>
var lastLiId = $(".album li:last").attr("id"); // minus one?
Run Code Online (Sandbox Code Playgroud)