HTML中的列表即使在应用了溢出和换行后也不能水平显示
Lists in HTML not displaying horizontally even after applying overflow and wrap
复制代码并运行html文件。把JavaScript文件放到scripts文件夹,css文件放到styles文件夹。
问题是li
元素没有以应该的方式水平显示。
当您运行它并填写详细信息并添加学生信息时,它将显示在html页面中。没有刷新填充另一个细节。再一次,它显示了。一开始的2 checkboxes
告诉我们视图的类型,这就是问题所在。我想让它水平显示。我不希望元素水平显示,一旦它越过ul
元素区域,我希望它给一个水平滚动,而不是一个新的行。
var name;
var age;
var dob;
var id;
var street;
var city;
var id1;
//Variable declarations
function ver() {
console.log("Vertical view");
$("#displayDetails").removeClass("hor").addClass("ver");
}
function hor() {
console.log("Horizontal View");
$("#displayDetails").removeClass("ver").addClass("hor");
}
$(window).load(function() {
// executes when complete page is fully loaded, including all frames, objects and images
console.log("window is loaded");
});
$(document).ready(function() {
// executes when HTML-Document is loaded and DOM is ready
console.log("Inside document.ready(function())");
$("button").click(function() {
console.log("name fetched");
name = $("#name").val();
age = $("#age").val();
dob = $("#dob").val();
street = $("#street").val();
city = $("#city").val();
// alert(city + "id " +id + "stret " + street);
console.log(age);
//Validation Results
var status;
status = new Validate();
var nameStat = true;
if (!status.validateName(name)) {
console.log("Name incorrect");
} else if (!status.validateAge(age)) {
console.log("age incorrect");
} else {
var a = new Student(name, age, dob, street, city);
}
$('input').val("");
});
});
//Validation Methods
var Validate = function() {
this.validateName = function(name) {
//alert(name);
if (name == "") {
console.log("Name cannot be blank");
return false;
} else {
return true;
}
/*else if(name == /[a-z]/)
{
console.log("Good name");
return true;
}*/
}
this.validateAge = function(age) {
console.log("validating age");
if (age == "") {
console.log("Age cannot be blank");
$("#age").focus();
return false;
} else {
return true;
}
/*else if(age==/[0-9]/)
{
console.log("Please enter a Valid age!");
}
else{return true;}*/
}
}
this.validateCity = function(city) {
if (city == "") {
alert("City name cannot be blank");
$("#city").focus();
return false;
} else {
return true;
}
}
this.validateStreet = function(street) {
if (street == "") {
alert("Street cannot be blank");
$("#street").focus();
return false;
} else {
console.log("Got Street");
return true;
}
}
this.validateDob = function(dob) {
if (dob == "") {
alert("DOB cannot be blank");
$("#dob").focus();
return false;
} else {
return true;
}
}
var count = 0;
var Student = function(name, age, dob, addressId) {
this.name = name;
this.age = age;
this.dob = dob;
this.addressId = addressId;
//alert("Street : " + addressId.street);
++count;
$("#displayDetails").append("<li id=count><input type='checkbox' onclick='delete1()'>" + " <div>" +
"Name: " + name +
"<br/>Age: " + age +
"<br/>Date of Birth: " + dob +
"<br/>Street: " + street +
"<br/>City: " + city
+ "</div>" + "</li>");
}
function delete1() {
$("#count").remove();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="styles/hor.css">
</head>
<body>
<b>Select View</b>
Vertical
<input value="vertical" type="radio" name="view" onclick="ver()" />Horizontal
<input value="horizontal" type="radio" name="view" onclick="hor()" />
<h2><i>Students Information Form</i></h2>
<input type="text" placeholder="Enter Name" id="name" />
<br/>
<input type="text" placeholder="Enter Age" id="age" />
<br/>
<input type="text" placeholder="dd/mm/yyyy" id="dob" />
<br/>
<input type="text" id="street" placeholder="street" />
<br/>
<input type="text" id="city" placeholder="city" />
<br/>
<button>Register</button>
<br/>
<div style="background-color:#999999;" id="box">
<ul id="displayDetails" class="hor ver"></ul>
</div>
<script src="scripts/script2.js"></script>
</body>
</html>
在CSS中
ul#displayDetails{
list-style-type: none;
display: inline-flex;
overflow-x: auto;
background-color: #999999;
max-width: 300px;
}
ul#displayDetails li{
padding-right:40px;
min-width: 100px;
}
也从ul
的父div
中删除background-color:#999999;
相关文章:
- 如何在映射数组中添加换行符
- JQuery:向多个匹配结果添加换行符的最简单方法
- 在文本区域中使用jQuery.text()保持换行符
- Internet Explorer中的文本换行错误
- 从Javascript警报中防止换行
- javascript替换换行符和特殊字符
- 换行符拆分返回“”;未定义”;
- javascript中换行的regexp
- 编辑数据库输入时在文本框上换行
- 在 JS 中添加字符串之前强制换行
- 如何使用web浏览器在NoSQL数据中呈现换行符
- 换行符插入jquery选择器
- jquery使用val()复制值似乎可以删除换行符
- 文本区域-获取每一行,找到换行符
- 处理字段中带有换行符的csv文件-node.js
- 使用jquery将单个换行符替换为span元素
- 有没有一种方法可以在单词溢出时换行?在换行之前,含义尽可能适合大多数单词
- 溢出隐藏不会文本换行
- 如何溢出文本而不是在元素中换行
- HTML中的列表即使在应用了溢出和换行后也不能水平显示