我想检查一个字符串是否以
- v{number}
Run Code Online (Sandbox Code Playgroud)
所以例如
hello world false
hello world - v2 true
hello world - v false
hello world - v88 true
Run Code Online (Sandbox Code Playgroud)
不完全确定如何去做这个 RegEx。
var str = 'hello world - v1';
var patt = new RegExp("/^ - v\d*$/");
var res = patt.test(str);
console.log(res);
Run Code Online (Sandbox Code Playgroud)
我怎么能修复上面的正则表达式?
我有一段代码,我试图包装在一个返回cookie值的函数中.
document.cookie.split(';').filter(function(s) {
return s.search('constituency=') == 1
})[0].split(/(=)/).slice(2).join('');
Run Code Online (Sandbox Code Playgroud)
在我的浏览器控制台中,这将完美地返回cookie值.我希望能够在另一个函数中使用此值,但是当我尝试将其包装在函数中时,它会显示为"未定义".
谁能帮助我理解为什么?
function splitValues() {
document.cookie.split(';').filter(function(s) {
return s.search('constituency=') == 1
})[0].split(/(=)/).slice(2).join('');
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个管理页面,并且仅允许具有角色2的用户由于某种原因而没有向我提供我期望的信息.
<?php
session_start();
require_once('includes/mysql_config.php');
$id = isset($_SESSION['id']) ? $_SESSION['id'] : header('location: login.php');
$user = mysqli_query($con, "SELECT * FROM users WHERE id =".$_SESSION['id']) || false;
if($user['role'] == '2'){
echo "Hello $user['name']";
}
else {
header('location: index.php');
}
?>
Run Code Online (Sandbox Code Playgroud)
当我做vardump($user)它给我输出1.
当我回应$_SESSION['id']它时它给了我正确的id(会话ID与用户id相同).
我需要从多维数组中获取最后6个值,我试图做这样的事情
for($i=0;$i<6;$i++){
$stats = array_shift($stats);
}
Run Code Online (Sandbox Code Playgroud)
但是在第一个array_shift之后我得到以下错误
PHP Warning: array_shift(): The argument should be an array
Run Code Online (Sandbox Code Playgroud)
是否有任何功能可以在PHP中执行此操作?
我有一个AJAX函数,我在AJAX上很糟糕.我想将值从PHP传递给AJAX.我设法通过使用:
<input type="text" id="price" onclick='ajaxFunction()' value="<?php echo $id; ?>" />
Run Code Online (Sandbox Code Playgroud)
然后在我的AJAX中:
document.getElementById('price').value;
Run Code Online (Sandbox Code Playgroud)
但我想通过使用HTML a href使其工作.
任何人都可以帮我找到可行的方法吗?
提前致谢!
该input元素似乎拖累了父元素div.为什么会这样?我该如何解决?
HTML
<div class="main">
<div class="one">
</div>
<div class="two">
<input type="text" /> <!-- Without this input, the page looks fine -->
</div>
<div class="three">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
css
.main>div {
display: inline-block;
height: 330px;
}
.one {
width: 18%;
background-color: #fbfbfb;
}
.two {
margin-left:10px;
width: 50%;
border: 2px solid #ddd;
}
.three {
margin-left: 10px;
width: 20%;
background-color: #bbb;
border: 5px dashed #ddd;
}
Run Code Online (Sandbox Code Playgroud)
我有一个13位数的值1231234123412,我想用点分割这个数字到下面的模式###.####.####.##.
结果值必须如下 123.1234.1234.12
如何使用javascript,angularjs甚至正则表达式将值分成4个块(###.####.####.##)?
我的画廊页面上有一个问题.我有JavaScript来处理用户菜单选择,但其中一个选项是返回主页,但它不起作用,因为On Click事件接管了页面上的所有链接,有没有办法解决这个问题?我在网上搜索了答案,但没有运气,谢谢.
$(document).ready(function() {
LoadGallery($('a[data-albumid]:first').data('albumid'));
$("a").click(function() {
var dir_path = $(this).data("albumid");
LoadGallery(dir_path);
return false;
});
});Run Code Online (Sandbox Code Playgroud)
<ul id="nav">
<li><a href="#" id="here">Gallery</a>
<ul>
<li><a href="#" data-albumid="images/gallery/fld01/">2014</a></li>
<li><a href="#" data-albumid="images/gallery/fld02/">2014</a></li>
<li><a href="#" data-albumid="images/gallery/fld03/">2014</a></li>
<li><a href="#" data-albumid="images/gallery/fld04/">2015</a></li>
<li><a href="#" data-albumid="images/gallery/fld05/">2015</a></li>
</ul>
</li>
<li><a href="index.html" id="home">Back to home</a></li>
<!-- This one never works! -->
</ul>Run Code Online (Sandbox Code Playgroud)
我对此代码有疑问:
$(document).ready(function() {
sweetAlert("a");// This is just a test, and it runs successfully by the way!!!
});
$("#login").keyup(check);
function check() {
$(this).val($(this).val().replace(/\s/g,"_"));
}
Run Code Online (Sandbox Code Playgroud)
浏览器正在加载文件,我从检查器中检查了它,并运行.ready脚本。但是它不能与.keyup一起使用。然后当我复制/粘贴行
$("#login").keyup(check);
Run Code Online (Sandbox Code Playgroud)
在控制台中,它可以成功运行。
如果需要,这是html表单:
<input type="text" name="login" id="login"/>
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助。
基本上我已经使用jquery事件提交了表单数据,以防止页面重新加载.现在,表格的信息没有显示?
$("#btn-ser1").click(function() {
$("#form").submit(function() {
alert("you are submitting" + $(this).serialize());
});
});Run Code Online (Sandbox Code Playgroud)
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<body>
<form method="post" id="form">
First Name :
<input name="fname">Last Name :
<input name="lname">Address :
<input name="address">Contact No. :
<input name="contact">Country:
<input name="country">City:
<input name="city">
</form>
<button type="button" id="btn-ser1">Serialize</button>
</body>
</html>Run Code Online (Sandbox Code Playgroud)