我有一个下拉菜单,我希望一些列表项在一行中.
见演示
你会注意到Tab One,有9行.我希望每行有三行,每行有三个项目.怎么能在CSS中完成?
HTML:
<div id="wrapper">
<ul id="menu">
<li><a href="#">Tab One</a>
<ul style="width: 300%;">
<li><a href="#">Column one</a></li>
<li><a href="#">Column one</a></li>
<li><a href="#">Column one</a></li>
<li><a href="#">Column two</a></li>
<li><a href="#">Column two</a></li>
<li><a href="#">Column two</a></li>
<li><a href="#">Column three</a></li>
<li><a href="#">Column three</a></li>
<li><a href="#">Column three</a></li>
</ul>
</li>
<li><a href="#">Tab Two</a>
<ul style="position: relative; left: -100%; width: 300%">
<li><a href="#">Tab 2</a></li>
<li><a href="#">Tab 2</a></li>
<li><a href="#">Tab 2</a></li>
</ul>
</li>
<li><a href="#">Tab Three</a>
<ul style="position: relative; left: -200%; width: 300%">
<li><a href="#">Tab …Run Code Online (Sandbox Code Playgroud) 我试图计算用户点击任何图像的次数.这就是我想出的:
var count = 0
$('document').ready(function() {
function countClicks() {
$('img').click(function() {
count++;
}
)};
)};
Run Code Online (Sandbox Code Playgroud)
我想知道这是否会起作用,如果这是我解决方案的最佳方法.另外,我将如何访问"计数"以供日后使用?例如,如果我输入一个基本条件,检查'count'是否大于10,它是一个单独的函数还是在'countClicks'函数内?谢谢你,如果这个问题过于简单,我很抱歉.
我找到了一个很棒的jsfiddle,有人制作并希望在我的项目中使用它的一部分:
http://jsfiddle.net/manuel/29gtu/
它适用于jsfiddle,但不适用于我的HTML文档.这是我的文件中的内容:
<!DOCTYPE html>
<html>
<head>
<script src="scripts/jquery-1.7.2.js"></script>
<script>
$("button").click(function() {
var id = $("#id").val();
var text = "icon-"+id;
// update the result array
var result = JSON.parse(localStorage.getItem("result"));
if(result == null)
result = [];
result.push({id: id, icon: text});
// save the new result array
localStorage.setItem("result", JSON.stringify(result));
// append the new li
$("#bxs").append($("<li></li>").attr("id", "item-"+id).html(text));
});
// on init fill the ul
var result = JSON.parse(localStorage.getItem("result"));
if(result != null) {
for(var i=0;i<result.length;i++) {
var item = result[i];
$("#bxs").append($("<li></li>").attr("id", "item-"+item.id).html(item.icon));
}
}? …Run Code Online (Sandbox Code Playgroud) 我试图看看用户点击的两个图像是否相同.我有一些代码可以检索被点击的图像的来源:
$('img').click(function() {
var path = $(this).attr('src');
});
我只需要一种方法来比较两个来源.我尝试将数据源存储在一个数组中,看看它们是否相等,但我无法让它工作:
var bothPaths = [];
$('img').click(function() {
var path = $(this).attr('src');
bothPaths.push(path);
});
if (bothPaths[0] == bothPaths[1]) {
alert("they match.");
} else {
alert("they don't match.");
}
Run Code Online (Sandbox Code Playgroud)
我会假设这会比较用户点击的前两个图像源,但我似乎在某个地方有问题.
我正在研究记忆匹配游戏.我有一些代码检查用户点击的两个图像是否具有相同的源,如果它们具有相同的源,则删除图像.
(function compareClicked() {
var lastclicked = "";
$("img").click(function() {
var path = $(this).attr("src");
if( lastclicked == path) {
$('img').hide(1000, function () {
$(this).remove();
});
}
else {
if( lastclicked != "") alert("Not a match");
}
lastclicked = path;
});
})();
Run Code Online (Sandbox Code Playgroud)
但是,正如您所看到的,当它们具有相同的源时,它会删除页面上的所有图像 - 即使用户没有单击它们.如何更改它以便仅删除用户单击的两个图像?
我有一个页面,用户可以编辑他们的信息.用户输入信息的方式之一是下拉菜单.我已经有了值,我需要在下拉菜单中将该值设置为活动选项.我知道用一堆if语句做最直接的方式:
if ($classVal == "Freshman") {
echo "
<select name='class'>
<option selected>Freshman</option>
<option>Sophomore</option>
<option>Junior</option>
<option>Senior</option>
</select>
";
} else if ($classVal == "Sophomore") {
echo "
<select name='class'>
<option>Freshman</option>
<option selected>Sophomore</option>
<option>Junior</option>
<option>Senior</option>
</select> </p>
";
} else if ($classVal == "Junior") { ... }
Run Code Online (Sandbox Code Playgroud)
这种方式对我有用,但我想知道是否有更好的方法来实现这一点.
我正在尝试检索用户点击的图像的图像源.这就是我所拥有的,它似乎没有起作用:
var imgSrc = getSrc(image)
function getSrc(image) {
$('img').each(function() {
$(this).click(function() {
$(this).attr('src')
}); //end click
}); //end each
} //end getSrc
Run Code Online (Sandbox Code Playgroud) 我有以下HTML:
<div id="wrapper">
<div class="p1">
<a href="#" class="quickFlipCta"><img src="Test Pictures/QuestionMark.gif" /></a>
</div>
<div class="p2">
<a href="#" class="quickFlipCta"><img src="Test Pictures/flower.gif" /></a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我有一个在用户点击链接时启动的功能:
$('a').click(function(){
//some code here
});
Run Code Online (Sandbox Code Playgroud)
在函数中,我想访问"包装器"div.这样做的最佳方式是什么?我试过了:
$('a').click(function(){
$(this).parent().parent().
//modification to wrapper
});
Run Code Online (Sandbox Code Playgroud)
但这似乎并没有奏效.